- 17.9K All Categories
- 3.4K Industry Applications
- 3.4K Intelligent Advisor
- 73 Insurance
- 537.2K On-Premises Infrastructure
- 138.6K Analytics Software
- 38.6K Application Development Software
- 6K Cloud Platform
- 109.6K Database Software
- 17.6K Enterprise Manager
- 8.8K Hardware
- 71.2K Infrastructure Software
- 105.3K Integration
- 41.6K Security Software
What are the process states in Unix/Linux?
In Unix/Linux operating systems, processes can be in one of the following states:
1. RUNNING & RUNNABLE
Let’s discuss these states in this article.
Fig: Process State transition diagram
RUNNING & RUNNABLE
When the CPU executes a process, it will be in a RUNNING state. When the process is not waiting for any resource and ready to be executed by the CPU, it will be in the RUNNABLE state.
SLEEPING state indicates the process is currently waiting on certain resources (like waiting on I/O, waiting on locks, application code making the process to sleep,…). There are two types of SLEEPING processes:
INTERRUPTABLE_SLEEP: When a process is in INTERRUPTABLE_SLEEP, it will wake up from the middle of sleep and process new signals sent to it.
UNINTERRUPTABLE_SLEEP: When a process is in UNINTERRUPTABLE_SLEEP, it will not wake up from the middle of sleep even though new signals are sent to it.
How to kill the SLEEPING Process ?
If the process is in INTERRUPTABLE_SLEEP state, then issuing SIGKILL signal (i.e. ‘kill -9’) to the process, will terminate the process immediately. On the other hand, if the process is in UNINTERRUPTABLE_SLEEP state, then the issuing SIGKILL signal will not terminate immediately. Only after the process completes its sleep/waiting operation it will terminate. Thus, if you would like to kill a process which is in UNINTERRUPTABLE_SLEEP state for a prolonged period then you have to reboot the system, there is no other way.
STOPPED state indicates that the process has been suspended from proceeding further. In Linux when you issue the ‘Ctrl + Z’ command it will issue a SIGSTOP signal to the process. When the process receives this signal it will be suspended/stopped from executing further. When a process is in STOPPED state, it will only handle SIGKILL and SIGCONT signals. SIGKILL signal will terminate the process, but the SIGCONT signal will put the process back into RUNNING/RUNNABLE state.
A process will terminate when it calls ‘system exit’ API or when someone else kills the process. When a process terminates, it will release all the data structures and the resources it holds. However, it will not release it’s slot in the ‘process’ table. Instead, the process will send a SIGCHLD signal to its parent process. Now it’s up to the parent process to release the child process slot in the ‘process’ table. The process will be in ZOMBIE state from the time the child process issues the SIGCHLD signal until the parent process releases the slot in the ‘process’ table.
How to kill the ZOMBIE Process ?
Issuing ‘kill -9’ on a Zombie process Id, it will not affect because ZOMBIE process doesn’t exist. However Zombie Process can be killed by sending a SIGCHLD signal to the parent process, using the below kill command:
kill -s SIGCHLD parent-pid
This signal tells the parent process to execute the wait() system call and clean up its zombie process.
NOTE: Sometimes if the parent process isn’t programmed properly to handle SIGCHLD signals, then the above command will not work. You have to kill the parent process of the zombie process.
How to find process state?
You can find process state from the following source:
a. Unix/Linux command-line tool ‘top’ will report the process state in the column ‘s’. Process status is reported with a single character.
R – RUNNING/RUNNABLE
S – INTERRRUPTABLE_SLEEP
D – UNINTERRUPTABLE_SLEEP
T – STOPPED
Z – ZOMBIE
Fig: top tool reporting
b. You can use web-based root cause analysis tools like ***Moderator action: link to commercial product removed as it is considered spam***, which will report the process states.