Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
System information as of Fri Mar  9 19:40:01 KST 2012

  System load:    0.59               Processes:           167
  Usage of /home: 23.0% of 11.00GB   Users logged in:     1
  Swap usage:     0%                 IP address for eth1: 192.168.0.1

  => There is 1 zombie process.

  Graph this data and manage this system at https://landscape.canonical.com/

10 packages can be updated.
4 updates are security updates.

Last login: Fri Mar  9 10:23:48 2012
a@SERVER:~$ ps auxwww | grep 'Z'
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
usera     13572  0.0  0.0   7628   992 pts/2    S+   19:40   0:00 grep --color=auto Z
a@SERVER:~$ 

How to find that zombie process?

share|improve this question
    
why dont you open the system monitor and search for the zombie process? –  Nickolas Jul 6 '12 at 8:00
    
How to do that on a headless no-X server? –  SabreWolfy Feb 27 '13 at 10:01

3 Answers 3

up vote 14 down vote accepted

To kill a zombie (process) you have to kill its parent process (just like real zombies!), but the question was how to find it.

Find the zombie (The question answered this part):

a@SERVER:~$ ps aux | grep 'Z'

What you get is Zombies and anything else with a Z in it, so you will also get the grep:

USER       PID     %CPU %MEM  VSZ    RSS TTY      STAT START   TIME COMMAND
usera      13572   0.0  0.0   7628   992 pts/2    S+   19:40   0:00 grep --color=auto Z
usera      93572   0.0  0.0   0      0   ??       Z    19:40   0:00 something

Find the zombie's parent:

a@SERVER:~$ pstree -p -s 93572

Will give you:

init(1)---cnid_metad(1311)---cnid_dbd(5145)

In this case you do not want to kill that parent process and you should be quite happy with one zombie, but killing the immediate parent process 5145 should get rid of it.

Additional resources on askubuntu:

share|improve this answer
    
The result you show in your answer is the the grep command itself, not the zombie process. It is the same mis-interpratation as Pablo made in his answer. The answer by Rinzwind below does actually look for the zombie process and list them. Another option could be to grep for "defunct" –  FvD Jul 23 '13 at 23:24
    
pstree -H your_desired_pid -p –  Greg Krsak Apr 9 at 16:45
    
Thanks Greg for adding to the discussion, but please remember this is a help site, just pasting a command without explaining anything is not helpful to most people coming here looking for help. –  Duncanmoo Apr 11 at 7:13

Even though this question is old I thought everyone deserved a more reliable answer:

ps axo pid=,stat=

This will emit two whitespace-delimited columns, the first of which is a PID and the second of which is its state.

I don't think even GNU ps provides a way to filter by state directly, but you can reliably do this with awk

ps axo pid=,stat= | awk '$2~/^Z/ { print }'

You now a list of PIDs which are zombies. Since you know the state it's no longer necessary to display it, so that can be filtered out.

ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'

Giving a newline-delimited list of zombie PIDs.

You can now operate on this list with a simple shell loop

for pid in $(ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }') ; do
    echo "$pid" # do something interesting here
done

ps is a powerful tool and you don't need to do anything complicated to get process information out of it.

share|improve this answer
    
awk is also a powerful tool which doesn't just split text but can also match it. +1 ... the others used grep where it's unnecessary and imprecise. –  0xC0000022L May 26 at 12:28

ps aux | awk '{ print $8 " " $2 }' | grep -w Z

From: http://www.cyberciti.biz/tips/killing-zombie-process.html

From the comments an improved one:

for each in `ps -ef | grep ” | grep -v PID | awk ‘{ print $3 }’`; do for every in `ps -ef | grep $each | grep -v cron | awk ‘{ print $2 }’`; do kill -9 $every; done; done

Careful though: this one also kills the proces.

share|improve this answer
    
still returns nothing. I think my way also wasn't wrong. –  Pablo Mar 9 '12 at 10:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.