How to find and Kill all ‘Zombie processes’ running on server?

In this article I will explain the ways to find and kill all Zombies on the server.

On Linux operating systems, a zombie process or defunct process is a process that has finished execution but still has an entry in the process table, allowing the process that started it to read its exit status.

It almost always means that the parent is still around. If the parent exited, the child would be orphaned and re-parented to init, which would instantly perform the wait. In other words, they should go away once the parent procedure is done.

A zombie process doesn’t respond to alerts.

1. How to find the Zombies from process list?

You can find out the Zombie processes in different ways:

# ps aux |grep "defunct"

After that run:

# ps aux |grep Z

2. How many Zombie processes running on your server? 

This is just for a count of Zombie processes on the server. It can be done in different ways.
Some examples are as follows:

# ps aux | awk {'print $8'}|grep -c Z
# ps aux | awk {'print $8'}|grep Z|wc -l

3. List the PID of Zombie?

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z
Z 3366
Z 3435
Z 3722
Z 4287
Z 5378

To kill these processes, you have to find the parent process first.

pstree -paul

Example output would be as follows:

[root@vps ~]# pstree -paul
  |   |-anvil,6577,dovecot
  |   |-config,25099
  |   `-log,6578
  |   |-httpd,1900,apache
  |   |-httpd,9428,apache
  |   |   |-php-cgi,1904,ctalk
  |   |   |-php-cgi,11989,ctalk
  |   |   `-php-cgi,11994,ctalk
  |   |-httpd,19203,apache
  |   |-httpd,22975,apache
  |   |-httpd,25197,apache
  |   `-httpd,30417,apache
  |   `-(khelper/3929,3)

This will give you the pid of the of the parent of the zombie process. Now you have to kill the parent process or restart the service.

[root@server]# kill -9

That’s it! Do share your comments.