Thursday, 9 August 2012

Process state codes in ps output



The output of the ps command shows a letter for the process state (depending on the output format you've asked ps to use, it may or may not be shown).
An example ps output (with most lines snipped for brevity):
[davidp@supernova:~]$ ps u
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
davidp    3995  0.0  0.4   3324  1956 pts/2    Ss   Aug17   0:00 /bin/bash
davidp   25049  0.0  0.8   7104  3908 pts/5    S+   Aug19   0:10 irssi
davidp   26180  0.0  0.1   2656   908 pts/0    R+   14:41   0:00 ps u
The 'STAT' column shows the state codes for each process.

Process state codes

The codes used are:
CodeMeaning
DUninterruptible sleep (usually IO)
RRunning or runnable (on run queue)
SInterruptible sleep (waiting for an event to complete)
TStopped, either by a job control signal or because it is being traced.
Wpaging (not valid since the 2.6.xx kernel)
Xdead (should never be seen)
ZDefunct (“zombie”) process, terminated but not reaped by its parent.
For BSD formats and when the stat keyword is used, additional characters may be displayed:
CodeMeaning
<high-priority (not nice to other users)
Nlow-priority (nice to other users)
Lhas pages locked into memory (for real-time and custom IO)
sis a session leader
lis multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+is in the foreground process group
D state occurs then the process is in uninterruptible sleep. This state is bad, because you can't do anything with the process in D state. 
Fortunately, process normally remains in such state not for so long. But if you have a heap of D state processes then some logic in system is disrupt. 
If that is happening, the very important thing is to determine where this unlucky sleep occurs. It is easy to do with ps command with l option. WCHAN column shows the name of the kernel function where the process is sleeping:
# ps axl | grep D
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
vass     13478  7.2  0.0   1732   624 pts/1    D+   17:36   0:00 find ./

1 comment:

  1. Good explanation...

    Mohan.Vunnam

    ReplyDelete