Thursday, April 12, 2012

How to avoid / Kill Zombies (Linux / Unix)

First of all, if you think you can kill Zombies; its ironic. Zombies are already dead. (Referring to processes)

With the above perspective in mind, lets investigate the issue. To find out if you have Zombie processes running on your *nix box. run the following command

# ps -elf|grep Z

This will launch and display a list of processes with Capital 'Z' character on your terminal/console. Let me explain why 'Z'. The 'ps' command returns result with a STAT field which has the current status of the processes. The character 'Z' refers to Zombie process.


ZOMBIE WAR
I don't care, I want the zombies on my system to be vaporized and GONE for ever!
In that case, your best bet is to find out the PPID (the parent process ID) of the zombie process and if possible terminate that parent process. This will result in termination of the zombie process. The other best way on a non-critical system is to reboot during maintenance window.

Are these things harmful for my system? Will they eat my system resources?
The best way to answer this by yourself is think about zombie lifestyle. Zombies don't eat or drink. They simply exist and are grossly - annoying. Similarly, if you have a Zombie processes on your system most likely it is just taking up space in your 'ps' and 'top' output screens. The zombie process is light on system and does not require much resource. It is different for an Orphan process, an orphan process is a fully functional executing processes who's parent has abandoned it and now the Grandparent 'init processes' has the custody of the process.

Causes of Zombie process creation?
It was discovered that there is a script that is being called with "nohup" causing zombie processes in the system. Further, it can be noted that the process could have been called using "nohup" followed by the shell script name / shell command. Since the parent process is not waiting for the child process to finish (Parent proc has abandoned the child proc). At several occasions, the above phenomenon leads to creation Zombie process.

How to avoid this from happening?
To avoid that from happening, best practise suggests usage of "wait" in the script.

MORE INFORMAITON:
"nohup Keeps a command running even after user logs off. The command will run as a foreground process unless followed by &. If you use nohup within a script, consider coupling it with a wait to avoid creating an orphan or zombie process."


the above extract is from

wait info
NAME
wait - await process completion

SYNOPSIS
wait [pid...]

http://pubs.opengroup.org/onlinepubs/7908799/xcu/wait.html