Zombie process is an inactive computer process, according to wikipedia article, "...On Unix operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table, allowing the process that started it to read its exit status. In the term's colorful metaphor, the child process has died but has not yet been reaped..."
So how do I find out zombie process?
Use top or ps command:
# top
OR
# ps aux | awk '{ print $8 " " $2 }' | grep -w Z
Output:
Z 4104 Z 5320 Z 2945
How do I kill zombie process?
You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.
You can kill zombie process using PID obtained from any one of the above command. For example kill zombie proces having PID 4104:
# kill -9 4104
Please note that kill -9 does not guarantee to kill a zombie process (see below for more info).
How do I automate zombie process killing?
Write a script and schedule as a cron job.
See also:
What are these zombie processes that show up in ps? I kill them but they don't go away! by David Newall.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- 10 Greatest Open Source Software Of 2009
- My 10 UNIX Command Line Mistakes
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email this to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: Sep/19/2006


{ 20 comments… read them below or add one }
My friend is using something as follow (he calls it as linux zombies kill script.. LOL)
for each in `ps jauxww | grep Z | grep -v PID | awk ‘{print $3}’`; do for every in `ps auxw | grep $each | grep cron | awk ‘{print $2}’`; do kill -9 $every; done; done
Hope it will be useful to someone.
help me…
awk: cmd. line:1: .{print
awk: cmd. line:1: ^ syntax error
awk: cmd. line:2: (END OF FILE)
awk: cmd. line:2: syntax error
ERROR: Conflicting format options.
Just copy and paste the code. I have fixed the css code problem.
grepping for the “word” Z won’t show Zombies that are also session leaders (such as Xorg) which show up as Zs
recommend ending with “| grep Z”
You should read the Wikipedia article more closely. There is no point sending a SIGKILL to a zombie process.
$ cat makezombie.c
#include
#include
#include
#include
int main(int argc, char *argv[])
{
pid_t child;
for (;;)
{
child = fork();
if (0 == child)
{
/* Whaddya know, I am the walrus^Wchild. Announce myself and
* exit immediately, making myself a zombie.
*/
fprintf(stdout, “Child PID is %ld\n”, (signed long int)getpid());
exit(0);
}
else if (child > 0)
{
/* I’m the parent. Loop without
* reaping the child.
*/
for (;;)
{
sleep(1);
}
}
else
{
/* fork() failed. Wait and try again. */
perror(“fork”);
sleep(1);
}
}
}
$ cc makezombie.c -o makezombie
$ ls -l makezombie
-rwxr-x— 1 youngman eng 9871 Mar 27 16:52 makezombie
$ ps
PID TTY TIME CMD
1769 pts/2 00:00:00 bash
2348 pts/2 00:00:00 ps
$ ./makezombie &
[1] 2351
$ Child PID is 2352
ps
PID TTY TIME CMD
1769 pts/2 00:00:00 bash
2351 pts/2 00:00:00 makezombie
2352 pts/2 00:00:00 makezombie
2353 pts/2 00:00:00 ps
$ kill -9 2352; echo $?
0
$ ps
PID TTY TIME CMD
1769 pts/2 00:00:00 bash
2351 pts/2 00:00:00 makezombie
2352 pts/2 00:00:00 makezombie
2356 pts/2 00:00:00 ps
$ kill 2351
$ ps
PID TTY TIME CMD
1769 pts/2 00:00:00 bash
2364 pts/2 00:00:00 ps
[1]+ Terminated ./makezombie
$
Plz tell me !
The difference between a thread and a process.
Plz give a detailed explanation.
I hope you will not let me down.
Thank you.
The first script has major issues with it. This is the one that I use
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
thanks.
I Got my ans of zombie Process.
The thread is some thing like background job for the process smiler to project count from 1 till 100 and the main purpose of the project is get each number value.
eg in our daily life is some programs can’t do any thing until it’s main job done like some sort of Anti Virus’s when you tried to do another job the program dosen’t respond to any command in the main time i’s in the same process but it take her own mem space :D
i hope i was any useful for you :D
#!/usr/bin/bash # # zombie_slayer [OPTIONS] # # -d # Just display the zombie processes and exit # # -h | help # Display help # # Default is to show processes and the ask what to kill (exits if any errors when killing processes) # function Z_Display { echo "" echo "Proc - PID - PPID - State - User" UNIX95= ps -eo comm,pid,ppid,state,user | awk '$4 ~ /Z/ { print $1,$2,$3,$4,$5 }' echo "" } function Z_Kill { read -p "Enter PPID to kill or 'exit' : " SLAY_PPID if [ "$SLAY_PPID" = "exit" ] || [ "$SLAY_PPID" = "" ] then exit fi ps -p $SLAY_PPID | grep -q $SLAY_PPID if [ $? -eq 0 ] then UNIX95= ps -o pid,user,state,comm -p $SLAY_PPID | \ awk '$1 ~ /^[0-9]*$/ { print "The program " $4 " with PID " $1 " is being run by the user " $2 " and is currently in state " $3 }' read -p "Are you sure you want to kill PID $SLAY_PPID ? Y|N : " COMMIT_KILL if [ "$COMMIT_KILL" = "Y" ] || [ "$COMMIT_KILL" = "y" ] then kill -9 $SLAY_PPID if [$? -eq 0] then echo "" read -p "Killed PID $SLAY_PPID. Run again? Y/N : " GO_AGAIN fi else Z_Kill fi else echo "Invalid PID. Try again." echo "" Z_Kill fi } function help { echo "Usage: zombie_slayer [-h | help -d]" echo "-d just display zombie processes and exit" echo "-h | help : This help" exit } if [ "$1" = "-h" ] || [ "$1" = "help" ] then help fi if [ "$1" = "-d" ] then Z_Display else Z_Display Z_Kill fi if [ "$GO_AGAIN" = "Y" ] || [ "$GO_AGAIN" = "y" ] then Z_Display Z_Kill fi echo ""Updated and tested with HP-UX 11i, Solaris 10, Debian, RHEL4 and SUSE 10
#!/usr/bin/bash # # Zombie Slayer # # zombie_slayer [OPTIONS] # # -d # Just diplay the zombie processes and exit # # -h | help # Display help # # Default is to show processes and the ask what to kill # function Z_Display { echo "" echo "PID - PPID - State - User - Proc" UNIX95= ps -eo pid,ppid,state,user,comm | awk 'BEGIN { count=0 } $3 ~ /Z/ { count++; print $1,$2,$3,$4,$5 } END { print "\n" count " Zombie(s) to slay." }' echo "" } function Z_Kill { read -p "Enter PPID to kill or 'exit' : " SLAY_PPID if [ "$SLAY_PPID" = "exit" ] || [ "$SLAY_PPID" = "" ] then exit fi ps -p $SLAY_PPID | grep -q $SLAY_PPID if [ $? -eq 0 ] then UNIX95= ps -o pid,user,state,comm -p $SLAY_PPID | \ awk '$1 ~ /^[0-9]*$/ { print "The program " $4 " with PID " $1 " is being run by the user " $2 " and is currently in state " $3 }' read -p "Are you sure you want to kill PID $SLAY_PPID ? Y|N : " COMMIT_KILL if [ "$COMMIT_KILL" = "Y" ] || [ "$COMMIT_KILL" = "y" ] then kill -9 $SLAY_PPID echo "" read -p "Killed PID $SLAY_PPID. Run again? Y/N : " GO_AGAIN else Z_Kill fi else echo "Invalid PID. Try again." echo "" Z_Kill fi } function help { echo "Usage: zombie_slayer [-h | help -d]" echo "-d just display zombie processes and exit" echo "-h | help : This help" exit } if [ "$1" = "-h" ] || [ "$1" = "help" ] then help fi if [ "$1" = "-d" ] then Z_Display else Z_Display Z_Kill fi if [ "$GO_AGAIN" = "Y" ] || [ "$GO_AGAIN" = "y" ] then Z_Display Z_Kill fi echo ""Quick ‘n dirty hack:
ps ax | awk ‘{ if ($NF == “”) print $1 }’ | xargs kill -9
I guess the html is stripped, hope at least one works, I mean $NF == defunct between “less than” and “greater than”:
ps ax | awk ‘{ if ($NF == “<defunct>″) print $1 }’ | xargs kill -9
ps ax | awk ‘{ if ($NF == “\”) print $1 }’ | xargs kill -9
You need to send the parent process a SIGCHLD or kill it
ps -eo pid,ppid,user,args,stat –sort stat | grep Z | awk ‘{ print $2 }’ | sort -u
gives you the parent process id(s)
kill -s SIGCHLD
or
kill
…
First things first, I am amazed at the amount of time so many people have put into dealing with such a non-issue. Zombie processes are dead, they consume nearly zero system resources. The only time you should be concerned is if you have a large number of them and said number is continuing to grow, in which case getting rid of the zombies is not your problem. You need to find out why you have them in the first place. Removing them is like taking a cold tablet, you are deling with the symptom, not the real problem.
That said, you should never, ever be using ‘kill -9′, that is an absolute last-ditch resort for dealing with a system that is almost non-functional or in some other critical state. Having a few zombie processes tying up nearly no resources at all is not a critical state, and using kill -9 is like chasing a mouse with a heavy hammer; you’re not likely to get the mouse, but you may do extensive damage to everything around you in the process.
So, what to do? find out what is spawning these processes, and why it is not shutting them down when they exit. See if there is a patch that fixes the issue. Make a report to the maintainers of the package. Restart the parent process. Or to reiterate, find out the cause of the problem and fix that.
ps -ef | grep defunct | awk ‘{ print $3 }’ | xargs kill -9
if u want to kill a zombie. just shoot it till it stops moving. its that simple. u should probably shoot the forhead. or the noggin. use a machete or a shotgun seem to work well. when the zombie apocolyps comes. set up traps and execute them. at costs dont let ur zombie bite u.
I know this is old but WTH -
I wrote the script above because we had several developers on a group of HPUX boxes testing a complicated MPE ported application. In many situations runaway processes would create zombie children which would alert us to problematic code. This script would tell me what process created them and who the developer was who kicked it off. Very helpful to me, and I thought that someone, somewhere might benefit from it. Since it is still here and ya’ll are finding it when you search for “how to Kill Zombie processes” it looks like maybe I was right :) Maybe someone learned some basic scripting skills too ;) Isn’t that what the internet is for?
ps aux | awk ‘{ print $8 ” ” $2 }’ | grep ‘Z’ |awk ‘{print $2}’ |xargs kill -9
Nice comments by Paul and Steveus
I even like a youtube video titled as “How to Kill a Zombie”
Do search and watch it, Its a must lesson for all of the geeks here !!!
Oops I forgot to say – Nice document by Nixcraft and best feature is I can save it as PDF.
Thanks!!