Process States

From COMP15212 Wiki
On path: Processes 1: Processes • 2: Context • 3: Process Control Block (PCB) • 4: Multi Threading • 5: Threads • 6: Interprocess Communication • 7: Process Scheduling • 8: Scheduler • 9: Process States • 10: Process Priority
Depends on ProcessesScheduler

A ‘simple’ computer has one processor so it can execute one process at any time. You may want to do more than this and a ‘multi-tasking’ operating system provides the illusion that you can.

If there is more than one process to execute, one is chosen and any others are queued waiting for a turn. After some time of execution the executing process may be moved back into the queue so that another process can proceed. The exact basis on which the processes are chosen for running or eviction depends on the particular scheduler employed.

One reason for ceasing to execute a particular process is that it cannot currently make progress; it is said to be ‘blocked’. A process is blocked when it waiting for I/O devices, communications etc. or it has deliberately gone to ‘sleep’ for a while.

If a process does not block, one way of scheduling other processes is called “time slicing”. This lets a process run for a certain time and then forces it to swap for one of the waiting processes. These processes are therefore either ‘running’ (the one lucky one at this moment) or ‘ready’ (a.k.a. ‘waiting’) for their turn.

process_states

Example: a word processor reads characters from the keyboard. When it is ready for the next character it will become ‘blocked’ until you press a key – a long time as far as the computer is concerned. When you press a key the blocked process becomes ready and will be run in the (hopefully near) future.

  • A process which is ready may:
    • be scheduled by the OS and set running
    • be terminated by some outside influence (e.g. ‘kill’)
  • A process which is running may:
    • deliberately yield execution (becoming ready)
    • terminate itself (job complete)
    • be terminated by some outside influence (e.g. ‘kill’)
  • A process which is blocked may:
    • become unblocked and become ready (e.g. because …)
      • I/O has become ready
      • time has advanced
    • be terminated by some outside influence (e.g. ‘kill’)

And here we see a classic Finite State Machine (FSM)!

This model suffices most of the time. Sometimes some other states are included – e.g. for when processes are created or terminate. A more sophisticated explanation may also include them.

Demonstration

The process states should be evident if you visit the (interactive!) demonstration of a (simple!) scheduler.

Queuing

Any number of processes can be ‘Ready’ to be run at a given time. There is therefore a ready queue of processors waiting their turn for scheduling.

Any number of processes can be ‘Blocked’ at a given time. However processes can be blocked for different reasons. For an communications process, such as a pipe an input or an output should only ever ‘belong’ to a single process, so (at most) one task will block waiting for that. On the other hand, some blocks (e.g. sleep() may also have a queue of waiting processes.

Multicore processors

With a single core processor only one process can be ‘Running’ at any time. With more cores, more processes can be running, assuming they are available. (If not, then the cores are idle).


Also refer to: Operating System Concepts, 10th Edition: Chapter 3.1.2, pages 107-109


Articles on Processes
About this resource • Atomicity • Containers • Context • Context Switching • Daemons • Fork Unix • Hypervisor • Idle • Interprocess Communication • Multi Threading • Mutual exclusion • Pipes • Pointer Arithmetic • Process Control Block (PCB) • Process Priority • Process Scheduling • Process States • Processes • Queues • Queues Extra • Race Conditions • Real Time • Resources • Scheduler • Signal and Wait • Sleep • Starvation • Synchronisation • Thrashing • Threads • Unix Signals