Sunday, September 5, 2010

How to Kill zombie processes

How to Kill zombie process with same Parent Process ID

#ps -el | grep 'Z'

Above command displays all the zombie process in the server. If all the PPID's are same you can kill by using our well known command "Kill"

#kill -9 <PPID>

Suppose if the PPID's are different follow the below steps.

# kill -9 `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`

Explantion of the above command

ps -A    -ostat,ppid,pid,cmd

this part of command displays the output with only the processes Status,Parent PID,PID and command which runs the processes

Example:
STAT  PPID   PID CMD
Ss    8782  8784 -bash

grep -e '^[Zz]

this part piped with the command to pullout the Zombie process from the list

awk '{print $2}

this is to pull out the PPID from the result displayed.

Atlast the command forms like below and kills all the zombie process

# kill -9 `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`

This is how to kill the zombie process.