Process states: running, waiting, stopped or zombie?
Video 070 of 140 in Virtualization Foundations, in the unit “Processes, threads and scheduling”. 4:20, with English and Hindi audio.
A busy server can run hundreds of processes at once. The state column in the ps command tells you what each one is doing right now: running, sleeping, stopped, waiting on a device, or finished but not yet cleaned up. Knowing these letters helps you tell a healthy busy server from one that is stuck on slow storage. This article explains each state, how a process moves between them, and how to read the column yourself.
What you will learn
- The state column in ps shows what each process is doing right now.
- R means running or ready to run, S means sleeping, and T means stopped on purpose.
- D means waiting on a device, usually a disk, and even a forced kill has to wait.
- Z marks a finished process whose parent has not yet read how it ended.
What the process state letters mean
Every process has a state, a short letter code that says what it is doing at this moment. A process in state R is running on a CPU, or it is ready and waiting in line for one. A process in state S is sleeping. It waits for something, such as network data or a timer, and it wakes up when that thing arrives.
T means the process is stopped. Someone paused it on purpose, for example by pressing Ctrl and Z in a shell. D is the state that needs the most care. It means the process is waiting on a device, usually a disk, and it cannot be interrupted while it waits.
A process moves between these states many times a second. It is ready, gets a CPU, runs, asks for data that has not arrived, and sleeps. When the data comes, the system wakes it, and it is ready again. The state column is a snapshot of where each process is at the moment you look.
Reading the state column with ps
The ps command lists processes. Adding the stat keyword shows the state column. The first letter is the main state, and any extra letters add detail. A plus sign means the process is in the foreground, the one you are typing into.
ps -eo stat,pid,comm | head -n 5Your own shell is a process too. It spends most of its time waiting for you to type, so its main letter is usually S.
ps -o stat,comm -p $To see the whole picture, count how many processes are in each state across the machine. A busy server with many D letters needs attention.
ps -eo stat | sort | uniq -cWhy state D and state Z need attention
A process in state D can stay stuck for as long as its device is slow or gone. Even a forced kill, the strongest stop message the system sends, must wait for that wait to end. When many processes sit in D together, check the storage path first, because the program is usually not the cause.
A zombie is a process that has finished running but is still listed, because the program that started it has not yet read how it ended. A zombie uses almost no memory or CPU, so killing it does nothing. The fix is to make the starting program read its result, or to restart that program.
Note: A process that stays in state D usually points to storage. Check the disks and any network storage it uses before you restart programs.
Read the process states on your own machine
You need a Linux terminal. You will read the state letters of a few processes, then count the states across the whole machine.
List the first five processes with their states. Look at the first letter of each state.
ps -eo stat,pid,comm | head -n 5What you should see: The STAT column shows the state. The first letter is the main state, and extra letters add detail.
Check the state of your own shell, which is waiting for you to type.
ps -o stat,comm -p $What you should see: Your shell is usually in state S, because it waits for typing.
Count the processes in each state on the whole machine. A large count under D is the one to investigate.
ps -eo stat | sort | uniq -cWhat you should see: Each line gives how many processes share one state letter, across the whole machine.
Terms
- Process state
- The short code, such as R or S, that shows what a process is doing right now.
- Runnable
- A process that is ready to use a CPU and may be waiting in line for one.
- Zombie
- A process that has finished running but is still listed, because its starting program has not read how it ended.
Check yourself
Which state letter means a process is waiting on a device and cannot be interrupted?
D. Even a forced kill has to wait until that wait ends.
Why does killing a zombie process do nothing?
A zombie has already finished and uses almost no memory or CPU. Make the starting program read its result, or restart that program.
What does a plus sign in the STAT column mean?
The process is in the foreground, the one you are typing into.
Previous: Process and thread: what is the difference?. Next: The scheduler: who gets a CPU, and for how long?.