how do I detect and kill zombie processes left from the command line of a Linux terminal?
-
1You 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
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.
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) }'
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
-
1While 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