Finding zombie processes

Posted by sebastian on Fri 30 Sep 2005 at 12:07

Tags: none.

If you have a server which is not working very well, it is posible that the process that you want to use is in a zombie state. You can see that there is a zombie process with top for example. But with top you can't not alway see which process it is.

If we use the following command we can see which process are zombies.

ps -el | grep 'Z'

With a normal ps -el command you see an output with in the second colum the state of the process. Here are some states:

S : sleeping
R : running
D : waiting (over het algemeen voor IO)
T : gestopt (suspended) of getrasseerd
Z : zombie (defunct)

The output under this text is an example. We can see that dovecot-auth is the zombie.

[root@s324 /]# ps -el | grep 'Z'
F S   UID   PID  PPID  C PRI  NI ADDR    SZ WCHAN  TTY          TIME CMD
1 Z     0  1213   589  0  75   0    -     0 funct> ?        00:00:00 dovecot-auth 

For the information in Dutch you can lookup my website.

 

 


Posted by Anonymous (85.65.xx.xx) on Fri 30 Sep 2005 at 13:09
to reduce noise in results, I allways use the command:
$ ps aux | grep " Z. "
(notice the whitespaces and the regex dot)

[ Parent | Reply to this comment ]

Posted by matej (158.193.xx.xx) on Fri 30 Sep 2005 at 17:02
alias Zombie='ps ex|awk "\$3==\"Z\"{print \$1, \$5}"'

[ Parent | Reply to this comment ]

Posted by Anonymous (82.181.xx.xx) on Fri 30 Sep 2005 at 19:22
So what should one do to kill those zombies for good? Does anything short of rebooting help?

[ Parent | Reply to this comment ]

Posted by stoffell (81.164.xx.xx) on Fri 30 Sep 2005 at 19:45
Depends on why it's a zombie.. Sometimes it's enough to kill (or restart) the parent process..

---
stoffell

[ Parent | Reply to this comment ]

Posted by Anonymous (84.176.xx.xx) on Tue 4 Oct 2005 at 03:18
The zombie process only contains the return value of the child, the parent should normally wait for that return value.. if it doesn't a zombie process will come up. (Application Bug)

[ Parent | Reply to this comment ]

Posted by Anonymous (84.4.xx.xx) on Fri 30 Sep 2005 at 21:19
ps -N r for non running processes
ps h for no header
ps -os,pid for display only state and pid

put it all together :

ps hr -Nos,pid

for zsh users :

now, you want to treat it line by line :
${(f)"$(ps hr -Nos,pid)"}

keep only the lines beginning with Z :

${(M)${(f)"$(ps hr -Nos,pid)"}:%Z*}

last think : you only need pids, so remove the Z caracter :
${${(M)${(f)"$(ps hr -Nostate,pid)"}:%Z*}#Z }

you can now create your new function :

zombies() {
echo ${${(M)${(f)"$(ps hr -Nostate,pid)"}:%Z*}#Z }
}

regards,
khatar


[ Parent | Reply to this comment ]

Posted by Anonymous (68.154.xx.xx) on Sun 30 Oct 2005 at 10:52


ps -A -ostat,ppid,pid,cmd


Gives us all processes , stat[e] p[arent]pid, pid, and c[om]m[an]d


like this :
STAT PPID PID CMD
S 0 1 init [3]
SN 1 2 [ksoftirqd/0]
S< 1 3 [events/0]




what are we looking for ?
Zombies, my man, Zombies with a capital Z
so lets grep for it. with something like grep -e '^[Zz]' to be safe


ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'


So here we said:
list all processes,
show me the good stuff, like stat[e] p[arent]pid, pid, and c[om]m[an]d
Then, send the output to grep,
because I only want the lines that start with a Z or z .
Now let's restart the parent processes and shake out the zombie generation. my favorite way is kill -HUP then with the help of our friend the backtick we get

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




now the commands read:
restart the parent by listing all processes and showing stat,ppid,pid and cmd, grepping out the lines starting with Z or z
then using awk to select only the parent pid
from the output.



Fu-matic for the people


[ Parent | Reply to this comment ]

Posted by Anonymous (82.47.xx.xx) on Thu 20 Jul 2006 at 16:55
You rock!!!!

[ Parent | Reply to this comment ]

Posted by Anonymous (88.217.xx.xx) on Sat 8 Dec 2007 at 01:18
And what to do if the ppid is 1 (init)?

[ Parent | Reply to this comment ]

Posted by Anonymous (121.243.xx.xx) on Wed 20 Feb 2008 at 04:57
The command

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

rocks

[ Parent | Reply to this comment ]

Posted by Anonymous (203.91.xx.xx) on Tue 24 Jun 2008 at 11:54
I tried this command on AIX ans Solaris. it's NOT working, zombie is still there...

[ Parent | Reply to this comment ]

Posted by Anonymous (84.109.xx.xx) on Sun 26 Apr 2009 at 11:05
How can I get the termination time of a certain zombie process?

Thanks!

sternr

[ Parent | Reply to this comment ]

Posted by Anonymous (115.248.xx.xx) on Wed 29 Dec 2010 at 06:24
Nice Command
Just killing PPID for a Zombie ,its cleared

Thanks
Ramkumarcrk

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 150 votes ~ 0 comments )