Skip to content

Linux Foundations / Manage a Linux host ยท Step 30 of 50

Lesson: Process statesSwitch
โ† Linux Foundations

System administration

Process states

Read the STAT column and understand running, sleeping, stopped and zombie.

At any moment, a process is in one state. Reading it tells you whether the process is working, waiting or finished.

The main letters

| Code | Meaning | | --- | --- | | R | running, or ready to run | | S | interruptible sleep, waiting for an event | | D | uninterruptible sleep, usually waiting on I/O | | T | stopped by a job control signal | | t | stopped by a debugger while tracing | | Z | zombie: ended but not reaped | | I | idle kernel thread (newer kernels) |

bash
$ ps -eo pid,stat,comm
    PID STAT COMMAND
      1 Ss   systemd
      4 I<   kworker/R-rcu_g
   2145 Ss   bash
   2290 T    vim
   2301 R+   ps

Most processes on a quiet system are sleeping. A shell waiting for you to type uses no CPU. R includes processes queued for a CPU, not only those executing at this instant.

Two kinds of sleep

In S, a signal can wake the process. In D, the process is in a kernel operation that must not be interrupted, often reading from a disk or a network file system. It usually does not react to signals, even SIGKILL, until the wait ends. Some kernel waits are "killable" and do respond to SIGKILL.

A short visit to D is normal. A process stuck there for a long time suggests a problem with storage or a mounted share.

Stopped is not sleeping

A stopped process does not run again until it receives SIGCONT:

bash
$ sleep 300 &
[1] 6010
$ kill -STOP 6010
$ ps -o pid,stat,comm -p 6010
    PID STAT COMMAND
   6010 T    sleep
$ kill -CONT 6010
$ ps -o pid,stat,comm -p 6010
    PID STAT COMMAND
   6010 S    sleep

Extra characters

Further characters in STAT add detail:

  • s session leader
  • + in the foreground process group
  • < high priority, N low priority
  • l multi-threaded
  • L has pages locked in memory

So Ss is a sleeping session leader, and R+ is a running foreground process.

You can also read the state from /proc:

bash
$ grep State /proc/$$/status
State:	S (sleeping)

Try it

Repeat the stop and continue example, checking STAT after each step. Then run ps -eo stat | cut -c1 | sort | uniq -c to count states on your system. The header line is counted too. Try it in the processes and cron lab.

Check your understanding

Process states

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.