Linux: Find and Kill Zombie Processes

Today we will learn about zombie processes. In particular, we will guide you to find and kill zombie processes on your Linux / Unix operating systems.

What is a zombie process?

On Linux / Unix  operating systems, a defunc process (aka zombie process) is a system process that has completed its execution, however it still show on the system process table. In other words, it’s an empty process, that is not executing any task, but still exist and has a process ID.

If there is a zombie process, there is a parent process around. And the same as in the movies, zombies do not react to normal ways of killing. On Unix / Linux it’s the same, you can’t kill the zombie, but you can kill the parent process, which will make the zombie process dissapear immediately.

Zombie processes can be found on almost any Unix / Linux operating system, and that also includes cPanel servers.

How can I list zombie processes on my system?

Zombies processes can be found by using the ps command, and piping a grep command with ‘defunc’ or ‘Z’ string in the “STAT” column.

Example: finding zombie processes using ps and grep.

ps aux |grep "defunct"

or

ps aux | grep 'Z'

Output example:

[[email protected]:~]ps aux | grep 'Z'
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 28115 0.0 0.0 103320 864 pts/0 S+ 09:26 0:00 grep Z
johndoe 3572 0.0 0.0 0 0 ?? Z 20:41 0:00 some.command

Kill zombie processes

Now in order to kill the zombie process, just kill the 3572 process and it should be gone. Let’s use pstree command to fund out the parent process

pstree -p -s 3572

The output should be something like:

init(1)---cnid_metad(1201)---cnid_dbd(3572)

This will show the pid of the of the parent of the zombie process. Now you need to kill the parent process.

[root@server]# kill -9 3572

All done, now you know how to find and kill zombie processes on Linux / Unix operating systems.  Do you know other ways to find and  kill zombie processes on Linux / Unix? Please share your knowledge with us.

Further reading:

About the Author: Esteban Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

Leave a Reply

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