One of the things a multitasking OS does is (obviously) run multiple tasks at once. (section 2) We shall talk about managing processes in the context of UNIX, but most OSs do broadly the same things.
So we have multiple simultaneous processes, and we must switch between them rapidly in order to create the illusion that they are all running simultaneously. For the moment, we assume that 'process' is synonymous with 'thread': each process has a single thread of execution. Multiple threads per process just complicate the description.
One thing we need is a data structure to record the current state of each process in order that when it is interrupted---while other processes are running---its state is preserved, and may be restored when next it gets a bite at the processor. UNIX keeps a 'process table' for this purpose, the enties of which are 'user pages'. (section 2.1.2)
In UNIX, with one thread per process, the information in the user page for each process is as follows:
book-keeping
Each 'user page' keeps track of one process---its file descriptors, its current program counter, its processor registers, bookkeeping info (like how much processor it's used recently), priority, where its memory is kept (we'll look at memory management a bit later), the 'signals' in which the process is interested, which user owns the process...
Each process also has a 'current state', one of 'running', 'runnable' or 'blocked' (section 2.1)
running---only one process may be running on a processor at any one time
runnable---a runnable process is ready and willing to run; it
just doesn't have a processor to run on. As the OS swaps between processes,
the processes change between 'running' and 'runnable'.
blocked---the process is waiting for something. It couldn't
run even if a processor was free. The 'something' the process is waiting
for could be file I/O, or a signal from another process, or a timer alarm
to be fired off.
The handy state diagram above shows how a process can move between different states.
Let's look at a real operating system. Linux is a flavour of UNIX. Essentially its processes may be 'RUNNING', 'RUNNABLE' and 'BLOCKED', but the Linux terminology differs slightly from ours. The process states in Linux are called:
Running | Linux does not explicitly distinguish between 'running' and 'runnable' processes. |
---|---|
Waiting | This is the 'blocked' state described above. In Linux, a blocked process may be 'interruptable' or 'uninterruptable'---'interruptable waiting' processes may be interrupted by signals, whereas 'uninterruptable waiting' processes are waiting directly on hardware conditions and may not be interrupted under any circumstances. |
Stopped | A process in this state has been 'stopped', usually by receiving a signal. A debugging tool may 'stop' processes in this way. |
Zombie | A process in the 'zombie' state has died, but not yet been removed from the process table. (It may be waiting for its parent process to remove it.) |