Finding zombie processes
Posted by sebastian on Fri 30 Sep 2005 at 12:07
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.
$ ps aux | grep " Z. "
(notice the whitespaces and the regex dot)
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
---
stoffell
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`
rocks
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
Thanks!
sternr
[ Parent | Reply to this comment ]
Just killing PPID for a Zombie ,its cleared
Thanks
Ramkumarcrk
[ Parent | Reply to this comment ]