Learn different process states in Linux. Guide explaining what are they, how to identify them and what does they do.
In this article we will walk you through different process states in Linux. This will be helpful analyzing processes during troubleshooting. Process states defines what process is doign and what it is expected to do in near time. Performance of system depends on major number of process states.
From the birth (spawn) till death (kill/terminate or exit), process has a life cycle going through several states. Some processes exist in process table even after they are killed/died, those processes are called zombie processes. We have seen much about zombie process in this article. Lets check different process states now. Broadly process states are :
- Running or Runnable
- Sleeping or waiting
How to check process state
top command lists total count of all these states in its output header.
top - 00:24:10 up 4 min, 1 user, load average: 0.00, 0.01, 0.00
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1018308k total, 187992k used, 830316k free, 15064k buffers
Swap: 0k total, 0k used, 0k free, 67116k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 19352 1552 1240 S 0.0 0.2 0:01.80 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
----- output clipped -----
See highlighted row named Tasks above. It shows total number of processes and their state-wise split up.
Later in above top output observe column with heading S. This column shows process states. In output we can see 2 processes in sleeping state.
You can even use ps command to check process state. Use below syntex :
# ps -o pid,state,command
PID S COMMAND
1661 S sudo su -
1662 S su -
1663 S -bash
1713 R ps -o pid,state,command
In above output you can see column titled S shows state of process. We have here 3 sleeping and one running process. Lets dive into each state.
Process state : Running
Most healthy state of all. It indicates process is active and serving its requests. Process is properly getting system resources (especially CPU) to perform its operations. Running process is process which is being served by CPU currently. It can be identified by state flag R in ps or top output.
Runnable state is when process has got all the system resources to perform its operation except CPU. This means process is ready to go once CPU is free. Runnable processes are also flagged with state flag R
Process state : Sleeping
Sleeping process is the one who awaits for resources to run. Since its on waiting stand, it gives up CPU and goes to sleep mode. Once its required resource is free, it gets placed in scheduler queue for CPU to execute. There are two types of sleep modes : Interruptible and Uninterruptible
Interruptible sleep mode
In this mode process awaits for particular time slot or specific event to occur. If those conditions occur, then process will come out of sleep mode. These processes are shown with state S in ps or top output.
Uninterruptible sleep mode
Process in this sleep mode gets its timeout value before going to sleep. Once the timeout sets off, it awakes. Or it awakes when waited-upon resources becomes available for it. It can be identified by state D in outputs.
Process state : Stopped
Process ends or terminates when they receive kill signal or they enter exit status. At this moment, process gives up all the occupied resources but does not release entry in process table. Instead it sends signal about termination to its parent process. This helps parent process to decide if child is exited successfully or not. Once SIGCHLD received by parent process, it takes action and release child process entry in process table.
Process state : Zombie
As explained above, while exiting process sends SIGCHLD to parent. During the time between sending signal to parent and then parent clearing out process slot in process table, process enters zombie mode. Process can stay in zombie mode if its parent died before it release child process’s slot in process table. It can be identified with Z in outputs.
So complete life cycle of process can be circle as –
- Removed from process table
Report any typo, feedback, correction, suggestions in comments below.