How to kill Zombie Processes on Linux
A Linux process notifies its parent process once it has completed its execution and has exited. Then the parent process would remove the process from process table. At this step, if the parent process is unable to read the process status from its child (the completed process), it won’t be able to remove the process from memory and thus the process being dead still continues to exist in the process table – hence, called a Zombie!
In order to kill a Zombie process, we need to identify it first. The following command can be used to find zombie processes:
$ ps aux | egrep "Z|defunct"
Z 108 103
ps ux | awk '{if($8=="Z") print}'
kill -s SIGCHLD 103
Z in the STAT column and/or [defunct] in the last (COMMAND) column of the output would identify a Zombie process.
Practically we can’t kill a Zombie because it is already dead! What can be done is to notify its parent process explicitly so that it can retry to read the child (dead) process’s status and eventually clean them from the process table. This can be done by sending a SIGCHLD signal to the parent process. The following command can be used to find the parent process ID (PID):
$ ps -o ppid= <Child PID>
kill -s SIGCHLD 103
ps -A -ostat,pid,ppid | grep -e '[zZ]'
Once you have the Zombie’s parent process ID, you can use the following command to send a SIGCHLD signal to the parent process:
$ kill -s SIGCHLD <Parent PID>
However, if this does not help clearing out the Zombie process, will have to kill or restart its parent process OR in case of a huge surge in Zombie processes causing or heading towards system outage, you will have no choice but to go for a system reboot. The following command can be used to kill its parent process:
$ kill -9 <Parent PID>
Killing the Parent Process
kill -9 103
Here, 103 is the parent id of our defunct process with PID 108.
If above process kill wont help then server reboot will help to fix the issue.
Comments
Post a Comment