kill zombie process in linux

How to Find & Kill Zombie Processes in Linux

Every running program, script, or task is a process in Linux. Also, one process can also spawn one or more processes, meaning one process can be the parent of other process. But sometimes, you may end up having zombie processes in your system. In this article, we will look at how to find & kill zombie processes in Linux.


What is Zombie process?

Typically, when a child process dies (or terminates), its parent process is informed about it so that it can cleanup the system resources previously used by its child process. But sometimes it may happen that a child process dies and its parent process is not aware of this incident. In such cases, the parent process thinks that its child process still exists. Such dead processes are known as zombie process. They are also known as defunct process. This is mostly the result of poor programming or software bugs. They do not cause any issues unless there are too many zombie processes occupying a large chunk of your system resources.


How to Find & Kill Zombie Processes in Linux

Here are the steps to find and kill zombie processes. You can use these steps in any Linux distribution, since these commands are available on almost every Linux flavor.


1. Find Zombie processes

Every Linux process can have any of the following states:

  • D = uninterruptible sleep
  • I = idle
  • R = running
  • S = sleeping
  • T = stopped by job control signal
  • t = stopped by debugger during trace
  • Z = zombie

One of the easiest ways to find zombie process is to run the top command. The S column in output displays the state of each process. If it is Z for any process, then it is a zombie process.

You can also use the ps command to get a list of zombie process. The 8th column of output of ps command displays the state of each process.

So we will run an awk command on the output of ps command, asking it to filter those records where the 8th column has value of Z.

$ ps ux | awk '{if($8=="Z+") print}'

Note the PID of all processes mentioned in the output of above command. Once we have PID of zombie processes, we need to find their parent.

We will use the following command for this purpose. Replace <child_id> with the PID of zombie process obtained above.

$ ps -o ppid= -p <child_id>


2. Kill Zombie process

Unfortunately, the only way to kill a zombie process, or free its resources, is to kill its parent. Once we obtain the PID of parent process of zombie processes, you can use the kill command to kill them.

$ kill -9 <parent_process_ID>

That’s it. In this article, we have learnt how to find and kill zombie processes. Since, you need to kill the parent of a zombie process, make sure to check if any other of its child process is running. Killing the parent will kill all child processes.

But remember that when you reboot the system, all zombie processes are destroyed anyway. So if you have a sibling process of a zombie process, that is still running, then it is better to leave its parent running, instead of killing it. If your system is running out resources and showing performance issues then you may need to kill the parent, and in turn, kill the zombie process.

Also read:

Disable Strict Host Key Checking in SSH
How to Create Superuser in Django
How to Print in Same Line in Python
How to Import from Another Folder in Python
How to Enable Apache MPM Prefork

Leave a Reply

Your email address will not be published.