Zombie process

What is a process?



A process is an instance of execution that runs on a processor. The process uses any resources that the Linux kernel can handle to complete its task.All processes running on Linux operating system are managed by the task_struct structure,which is also called a process descriptor. A process descriptor contains all the information necessary for a single process to run such as process identification, attributes of the process,and resources which construct the process. If you know the structure of the process, you can understand what is important for process execution and performance. The following figure explains you about the life cycle of the process.

Linux Process life cycle

What is a Zombie processes ?


When a process has already terminated, having received a signal to do so, it normally takes some time to finish all tasks (such as closing open files) before ending itself. In that normally very short time frame, the process is a zombie. After the process has completed all of these shutdown tasks, it reports to the parent process that it is about to terminate. Sometimes, a zombie process is unable to terminate itself, in which case it shows a status of Z (zombie).It is not possible to kill such a process with the kill command, because it is already considered dead. If you cannot get rid of a zombie, you can kill the parent process and then the zombie disappears as well. However, if the parent process is the init process, you should not kill it. The init process is a very important process so a reboot might be needed to get rid of the zombie process.

You can use the top command to get an overview of the current Zombies running in your server. For example.

Top Command Zombies

You can see around 12 Zombies running in your server. Try the following command to list all the zombies.

  • ps aux | awk ‘{ print $8 ” ” $2 ” ” $11}’ | grep -w Z

In my case the output was.

Ps command

Which shows most of them were due to the PHP binary. You may need to have a look in to the modules/setting which you have currently installed to figure out which module/setting is causing zombies to put a permanent solution.

Killing Zombie process


Note that Zombie process does not eat your ram memory but it will eat your CPU resources and if you decide to kill those process. Try

  • kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e ‘^[Zz]’ | awk ‘{print $2}’`

Which will kill all the zombie pid including the patent pid (PPID). You can also execute the above command via the cron task to kill them frequently. You can also try my script below to kill the ppid.

http://www.gnutoolbox.com/download/linux/scripts/killzombi.sh


Ps : Killing zombies via the above methods will not solve the problem permenently as it will persists again and again. So you have to figure out what is causing the process to zombie and try to fix it to solve the problem.