3

how do I detect and kill zombie processes left from the command line of a Linux terminal?

  • 1
    You can't kill the undead :P. Zombie process are dead process that are waiting to be "waited" with the parent process. In this process the parent knows how their children ended. When ever the terminal ends, this process will be inherit by init and init will "wait" them. So what you need is to kill/end the parent process. – anizzomc Apr 28 '11 at 15:17
4

You cannot kill a zombie process. If the parent process does not call wait(), you have to kill the parent process to remove the zombie.

1

You can grep for "defunct", or check for Z in the "state" output

ps -eo state,pid,cmd | grep "^Z"

If you want to kill it as well

ps -eo state,ppid | awk '$1=="Z"{cmd="kill -9 "$2;system(cmd) }'
0

Try:

ps aux

and look at the status column. Zombie are represented by letter Z.

0

try ps ax -o state -o ppid | awk '$1=="Z"{print $2}' | xargs kills all zombies

  • Can you expand your answer a little to explain what the code does? (I'm envisioning that maybe the ax is used to cut off their heads? :-) ) – fixer1234 Mar 30 '16 at 15:28
  • 1
    While this command may answer the question, providing additional context regarding why and/or how it answers the question would significantly improve its long-term value. Please edit your answer to add some explanation. – Toby Speight Mar 30 '16 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy