In Linux, what do all the values in the "top" command mean?
Asked Answered
S

3

76

When you run top and see all running processes, I've always wanted to know just what everything actually means. e.g. all the various single-letter state codes for a running process (R = Running, S = Sleeping, etc...)

Where can I find this?

Stovepipe answered 21/11, 2008 at 1:11 Comment(0)
E
149

The man page says what the state codes are mapped to, but not what they actually mean. From the top man page:

'D' = uninterruptible sleep
'R' = running
'S' = sleeping
'T' = traced or stopped
'Z' = zombie

'R' is the easiest; the process is ready to run, and will run whenever its turn to use the CPU comes.

'S' and 'D' are two sleep states, where the process is waiting for something to happen. The difference is that 'S' can be interrupted by a signal, while 'D' cannot (it is usually seen when the process is waiting for the disk).

'T' is a state where the process is stopped, usually via SIGSTOP or SIGTSTP. It can also be stopped by a debugger (ptrace). When you see that state, it usually is because you used Ctrl+ Z to put a command on the background.

'Z' is a state where the process is dead (it has finished its execution), and the only thing left is the structure describing it on the kernel. It is waiting for its parent process to retrieve its exit code, and not much more. After its parent process is finished with it, it will disappear.

Emileeemili answered 21/11, 2008 at 1:26 Comment(5)
This doesn't say what causes an S state. In contrast, I know that disk activity can cause a D state.Goosegog
@A-B-B: that's because there are many things which can cause an S state. The most common one is when the process is waiting for an event and/or timeout (select/poll/epoll, blocking read from the terminal or network, and many others).Emileeemili
Related answer with more detail: #224144Emileeemili
Is there a modern update available to this answer? I see processes with state code 'I' - and the man page doesn't say what that is!Sadye
If it's stopped by a debugger, isn't the state t, not T?Selfrighteous
M
19

You can use the command man top to look up the states:

D = uninterruptible sleep
I = idle
R = running
S = sleeping
T = stopped by job control signal
t = stopped by debugger during trace
Z = zombie
Manwell answered 21/11, 2008 at 1:13 Comment(3)
Hey dude! You stole my answer!Amine
RTFM is not a valid answer here, since the manual alone is insufficient to determine what the status really means.Jiffy
[~] # man top sh: man: command not found I know, I know: man7.org/linux/man-pages/man1/top.1.htmlSherborn
R
9

Programs like top and ps takes these values from the kernel itself. You can find its definitions in the source code here:

https://github.com/torvalds/linux/blob/3950e975431bc914f7e81b8f2a2dbdf2064acb0f/fs/proc/array.c#L129-L143

static const char * const task_state_array[] = {

    /* states in TASK_REPORT: */
    "R (running)",      /* 0x00 */
    "S (sleeping)",     /* 0x01 */
    "D (disk sleep)",   /* 0x02 */
    "T (stopped)",      /* 0x04 */
    "t (tracing stop)", /* 0x08 */
    "X (dead)",     /* 0x10 */
    "Z (zombie)",       /* 0x20 */
    "P (parked)",       /* 0x40 */

    /* states beyond TASK_REPORT: */
    "I (idle)",     /* 0x80 */
};

For more info see this question: https://unix.stackexchange.com/q/462098/79648

Resurrect answered 5/11, 2020 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.