Page 1 of 1

How to Find and Kill a Zombie Process on Linux Server?

Posted: September 11th, 2022, 5:19 am
by admin
A huge number of zombie processes could affect the free memory available for other processes. If you face too many zombies, there’s some serious issue with the operating system bug or the parent application. In that case, the remaining process IDs get monopolized by the zombies. If there remain no process IDs, other processes are unable to run.

Best things you have to do, is to kill that annoying zombie process. All you can do is, notifying its parent process so that it can again try to read the status of the child process, which has now become a zombie process, and eventually, the dead process gets cleaned from the process table.

Use the following command to find out the parent process ID. for example:

Code: Select all

root@srv8 ~]# ps aux | egrep "Z|defunct"
the result will looks like this:

Code: Select all

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     3696817  0.0  0.0 112812   976 pts/1    S+   04:51   0:00 grep -E --color=auto Z|defunct
or

Code: Select all

ps aux | awk '$8 ~ /^[Zz]/'
The 8th column in the output of the ps aux command displays the state of a process. You are asking to print all the matching lines where the state of a process starts with Z or z.
A process in Linux can have one of the following states:

D = uninterruptible sleep
I = idle
R = running
S = sleeping
T = stopped by job control signal
t = stopped by debugger during trace
Z = zombie

you can’t kill zombie processes as they are already dead.

Code: Select all

[root@srv8 ~]# kill -9 3696817
-bash: kill: (3696817) - No such process
notifying its parent process so that it can again try to read the status of the child process.

Code: Select all

[root@srv8 ~]# ps -o ppid=3696817
3696817
3696774
3696780
Once you get the child process ID of the zombie, send a SIGCHLD to the parent process....
Then you can kill it...

Code: Select all

[root@srv8 ~]# kill -s SIGCHLD 3696774
[root@srv8 ~]# kill -s SIGCHLD 3696780
[root@srv8 ~]#
Also... Please refer to my other post:
https://jsalfianmarketing.com/viewtopic.php?t=11