Process States

This is a unix-oriented description, but most real operating systems are fundamentally the same in this area.


Unix distinguishes between (usually) five different wait states, although systems can vary. The most common wait states are:

The "ps" command

The "ps" command tells you about processes on the system. It has a lot of options, but only a few are generally useful. Normally it only provides minimal information, the "-u" option asks for more, and is nearly always a good ide. Normally ps only tells you about processes that you created, the "-a" option makes it tell you about processes owned by other users, and is a good idea if you want to see some variety. The "-x" option is only useful if you really want to see everything that is going on, it makes even processes that are not attached to any terminal get listed when they are normally ignored. Options can be combined, the most useful form of ps is "ps -au". Here is the output produced by "ps -au" at 3.25pm on Wednesday 21st November 2001:
USER      PID %CPU %MEM   VSZ  RSS  TT  STAT STARTED      TIME COMMAND
root     9008  0.0  0.1   432  220  p3  R+    3:37PM   0:00.00 ps -au
root      366  0.0  0.2   924  516  v1  Is+   6Sep01   0:00.01 /usr/libexec/getty Pc ttyv1
root      367  0.0  0.2   924  516  v2  Is+   6Sep01   0:00.01 /usr/libexec/getty Pc ttyv2
root      368  0.0  0.2   924  516  v3  Is+   6Sep01   0:00.01 /usr/libexec/getty Pc ttyv3
root      369  0.0  0.2   924  516  v4  Is+   6Sep01   0:00.01 /usr/libexec/getty Pc ttyv4
root      370  0.0  0.2   924  516  v5  Is+   6Sep01   0:00.01 /usr/libexec/getty Pc ttyv5
root      371  0.0  0.2   924  516  v6  Is+   6Sep01   0:00.01 /usr/libexec/getty Pc ttyv6
root      372  0.0  0.2   924  516  v7  Is+   6Sep01   0:00.01 /usr/libexec/getty Pc ttyv7
stephen 98642  0.0  0.4  1404  948  p6  Is+  15Oct01   0:00.96 -tcsh (tcsh)
root     8291  0.0  0.2   924  580  v0  Is+  17Oct01   0:00.00 /usr/libexec/getty Pc ttyv0
stephen 81305  0.0  0.3  1260  836  p3  Is   Wed06PM   0:00.10 -tcsh (tcsh)
andrew   4817  0.0  0.3  1272  828  p1  Is   Tue12PM   0:00.03 -tcsh (tcsh)
andrew   4818  0.0  1.3  4716 3384  p1  I+   Tue12PM   0:00.36 pine -i
root     8476  0.0  0.3  1276  856  p3  S     1:23PM   0:00.06 _su (tcsh)
As you can see, it is arranged neatly in columns, one line per process. The columns are: The first letter of the State column is the most important one, it tells you which real state the process is in. The letters most commonly used are: Subsequent letters are very system dependent, the only interesting one is W which annoyingly doesn't appear in the sample, because (apparently) we have plenty of memory on this system. W means that the process has been swapped out (i.e. lost nearly all of its physical memory and been dumped on disc in the page file). The traditional rule was that any process in the Idle state would automatically be swapped out. If the system gets short of physical memory, processes in other states, in reverse order of their likelihood of waking up soon (i.e. S's are swapped out first, then D's, then P's and finally if the system still needs to recover more memory, R's get swapped out) If you ever see an RW process, you should probably consider buying more memory or changing the system settings.

A Zombie process is never swapped out (ZW never appears) because a zombie process has already given up nearly all of its pages anyway.

The other letters seen in the sample, "s" and "+", indicate that the process is a "session leader" (s) which is rarely of any interest, and doesn't really mean much, and (+) that it is the "foreground process" on a particulate terminal. The foreground process is the one that would receive any input typed on the keyboard, and would receive any kill signalls generated by control-Cs.

If you use all the interesting options: "ps -aux", you see every process that the system has. Sometimes that can be interesting.