Process States What is a Process?

3.1.2 Process States

The process changes its state over time One of the important items in the PCB is the process state. Processes change state during their execution, sometimes by themselves e.g. by making a system call, and sometimes due to an external event e.g. when the CPU gets a timer interrupt. The following graph shows the main states and transitions: running ready blocked schedule preempt wait for event event done terminated created Processes are created in the ready state. A ready process may be scheduled to run by the operating system. When running, it may be preempted and returned to the ready state. A process may also block waiting for an event, such as an IO operation. When the event occurs, the process becomes ready again. Such transitions continue until the process terminates. Exercise 33 Why should a process ever be preempted? Exercise 34 Why is there no arrow directly from blocked to running? Exercise 35 Assume the system provides processes with the capability to suspend and resume other processes. How will the state transition graph change? Note that the states pertain to the process or, as we’ll soon see, to a thread, not to the operating system. Graphically, processes may be represented by tokens that move from one state to another according to the possible transitions. At each moment, at most one process is in the running state, several may be ready to run but can’t because we only have one processor, and several may be blocked. The operating system mediates some of the transitions: it may do something, and as a result, change the state of a process. Technically, this may be done by moving the PCB of the process from one linked list to another, where one such list is the list of ready processes used by the scheduler, another is a list of blocked processes used by interrupt handlers, and so on. As processes may block for a variety of reasons, the blocked state may actually be implemented by multiple distinct lists. Real transitions between elements of the system may therefore actually look like this: 47 = process ready queue preemption CPU terminated new arrival waiting for disk waiting for terminal waiting for timer

3.1.3 Threads