Kill a Zombie process

To kill a zombie process:

1) Get the process ID (PID) of zombie process

[USER@HOSTNAME~]# ps aux | grep Z
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
user      7823  0.0  0.0      0     0 ?        Z    Apr04   0:00 [check_disk] <defunct>

[USER@HOSTNAME~]#

 

2) Get the Parent Process ID (PPID) of zombie process:

cat /proc/PID/status | grep -i ppid

* Replace PID with the actual Process ID (PID) that you’ve got from Step 1

 

3) Kill the Parent Process ID

kill -9 PPID

* Replace PPID with the actual Parent Process ID (PPID) that you’ve got from Step 2.

 

AUTOMATED:

As an alternative, you can combine all the above manual steps and put into a script. I’ve created a sample script for you:

ps aux | grep Z | grep -v “pts/0” | awk ‘{print $2}’ | grep -v PID > file-pid.txt
for i in `cat file-pid.txt`
do
cat /proc/$i/status | grep -i ppid | awk ‘{print $2}’ | xargs kill -9
done