How to Find and Kill Zombie Processes in Linux

In Linux, when a process finishes executing, it typically sends a signal to its parent process so the parent can read its exit status. However, if the parent process fails to read this status, the dead process remains in the process table as a “zombie”. While zombie processes do not consume CPU or memory, an excessive number of them can eventually exhaust your system’s process IDs (PIDs), preventing new processes from starting.

How to Find Zombie Processes

To identify if your Linux system has any zombie processes, you can use the top command. Open your terminal and run top. Look at the second line of the output (Tasks), which displays a count of sleeping, running, stopped, and zombie processes.

To list the specific zombie processes and find their PIDs, run the following command in your terminal:

ps aux | awk '$8 ~ /^[Zz]/'

How to Kill a Zombie Process

You cannot “kill” a zombie process using a standard kill -9 command because the process is already dead. The only way to remove a zombie is by forcing its parent process to acknowledge its death or by killing the parent process entirely.

First, find the parent process ID (PPID) of the zombie using this command (replace <zombie_pid> with the PID you found earlier):

ps -o ppid= -p <zombie_pid>

Once you have the parent PID, you can send it a SIGCHLD signal to tell it to clean up its child processes:

kill -s SIGCHLD <parent_pid>

If the parent process still does not reap the zombie, your only remaining option is to kill the parent process itself (kill -9 <parent_pid>). This will orphan the zombie process, causing the init or systemd daemon to adopt it and automatically clear it from the process table.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.