Problem Detail: When a computer OS supports multi-program, it needs to have a scheduling algorithm to handle which process will be run by the cpu. If a process is in state ‘blocked’ waiting for IO, the scheduling causes another process to be taken by the cpu while the process in state ‘blocked’ is waiting for a response I/O. In this situation, when the process returns to state ‘ready’ and then runs, how does the cpu know which process to run and where it was stopped ?
Asked By : SystemWork
Answered By : Wandering Logic
The scheduling algorithm is largely irrelevant. What is relevant is how the Operating System kernel saves information about requests it has made for which it is awaiting replies. When we say that a process is in state “blocked” we don’t really mean that there is a variable somewhere called state to which we have assigned the value running or blocked or waiting. Rather we have a bunch of different lists or queues in the system and we move the process from one queue to another queue to change the state. (Or more technically, we move a pointer to the data structure that represents the information about the process.) The information we record about a process includes all the information we need to resume running the process (the program counter to the last instruction it executed, plus the values of all its registers, plus pointers to its page table.) There is one queue for all the processes that are ready-to-run. When the scheduler (whatever kind of scheduler it is) decides that it is time for a different program to run it moves the pointer to the currently running process on to the ready-to-run queue and then pulls some other process off the ready-to-run queue, and resumes that process (restore all its registers and then jump to the next instruction in the process.) If a process makes an i/o request then it gets placed in a queue specific to that i/o device. (So there will be one queue for the keyboard, another for the mouse, another for the disk-drive and yet another for the wireless network.) When the process make the i/o request it gets moved to the correct queue for the kind of i/o it requested, the the operating system selects a different process from the ready-to-run queue. When an i/o device sends the response to a request (for example, you press a key on the keyboard, which causes an interrupt, which causes the processor to jump to the keyboard interrupt handling routine) the resulting data will be put in an appropriate buffer and then the process that was blocked waiting for that data will be moved off of the keyboard queue and back on to the ready-to-run queue. The os will then return from the interrupt (to the process that was running at the time the interrupt occurred) and then some time later it will decide to schedule in another process (which might or might not be the process that just got the data from the keyboard.)
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/32216 Ask a Question Download Related Notes/Documents