Interestingly, it seems that many search engines want to provide my blog as a result when folks want to know something about zombie processes, even though this site has nothing to do with them per se. As such, I will discourse for a bit on the seemingly morbid topic of Zombie Processes, this site’s namesake.
What is a zombie process?
When a process finishes execution, it will have an exit status to report to its parent process. Because of this last little bit of information, the process will remain in the operating system’s process table as a zombie process, indicating that it is not to be scheduled for further execution, but that it cannot be completely removed (and its process ID cannot be reused) until it has been determined that the exit status is no longer needed.
When a child exits, the parent process will receive a SIGCHLD signal to indicate that one of its children has finished executing; the parent process will typically call the wait() system call at this point. That call will provide the parent with the child’s exit status, and will cause the child to be reaped, or removed from the process table.
How do I see if there are zombie processes on a system?
Run “ps aux” and look for a Z in the STAT column.
How do I remove zombie processes from a system?
Well, first you can wait. It’s possible that the parent process is intentionally leaving the process in a zombie state to ensure that future children that it may create will not receive the same pid. Or perhaps the parent is occupied, and will reap the child process momentarily.
Secondly, you can send a SIGCHLD signal to the parent (“kill -s SIGCHLD <ppid>“). This will cause well-behaving parents to reap their zombie children.
Finally, you can kill the parent process of the zombie. At that point, all of the parent’s children will be adopted by the init process (pid 1), which periodically runs wait() to reap any zombie children.
Why did you name your blog Zombie Process?
RSS Feed - All
Monday, 9 Feb 2009 at 5:46 am
Trying to kill follow the above process. but no result is same ….
Last try to “killall pid” and and the zombie and its parents are cleared from the process list..
Riyad
Tuesday, 10 Mar 2009 at 3:32 pm
ps -eo pid,ppid,user,args,stat –sort stat
ppid is the parent process id
Sunday, 26 Apr 2009 at 3:48 am
Hey,
How can I know when a certain zombie process has terminated?
Thanks ahead!
–sternr
Friday, 15 May 2009 at 2:56 pm
@sternr:
Sorry to say that there is no indication that a zombie process has been reaped, except by watching the process table to see when it drops off.
Sunday, 24 May 2009 at 2:54 am
So Mike what u mean to say is until wait() function has been called by the parent process, the child remains as a zombie process?
If yes, then does that mean that it is mandatory to call the wait() function after the child exits?
Thanks ahead
Jatinder
Thursday, 11 Jun 2009 at 12:17 pm
Jainder:
“Mandatory” may be a strong word, but it is certainly good programming practice. If the process is long-running (a daemon, for example), and spawns many children that are never reaped, there will be many zombie processes milling about. In the case of a short-running process, the zombie children will be adopted by the init process when the parent is terminated, and the init process will take care of reaping them.
So, it’s not “mandatory,” but I would definitely characterize it as “highly, highly, highly recommended.”
Thanks,
Mike
Sunday, 5 Jul 2009 at 5:29 am
what happens when we directly send kill signal to
zombie process by
kill -9 pid
pid -zombie process pid
Thursday, 9 Jul 2009 at 1:25 pm
I suppose it technically depends on the OS implementation, but I would not expect “kill -9″ to eliminate the zombie from the process table. The process is already dead. Killing the parent of the zombie would eliminate the zombie, but I don’t think that’s what you are asking.
To be clear, zombie processes consume so few system resources that it should not be a concern to have several lingering around. It would be a concern if there are a lot, but that would likely mean that there is a significant bug in a component of your software stack…
Thanks,
Mike
Wednesday, 9 Dec 2009 at 1:19 am
i didn’t understood the second method of killing the zombie process,since the SIGCHILD signal is given to parent when child exits.So hw can it remove the zombie process?
Wednesday, 9 Dec 2009 at 11:17 am
If there is an issue in the design of the program for the parent process, it may have missed or otherwise not processed the initial SIGCHLD that was issued when the child process exited. This gives the parent process another chance to correctly handle the terminating child (presumably, the parent process is in a different state, and may be able to correctly process the signal this time around).