How to kill All Zombie Processes Running on the Server?

 

A process in its terminated state is called a zombie process. A zombie process is also known as a defunct process.

Did you ever notice some processes with status “Z” on your server while you are checking the server monitoring?. These are Zombie processes. Which means that the parent is still alive. If the parent process is exited, then the child would be orphaned and re-parented to init, which would immediately perform the wait on the process on the server.

 

List the Zombie processes running on the server

We can list these processes in different ways. Some of the commands are listed below to view the zombie process. Please see the commands with examples.

1) Login to the server as root user.

2) Run the below command to see the zombie process.

# ps aux |grep “defunct”

3) The output will be as follows.

# ps aux |grep “defunct”

manu      3366  0.0  0.0      0     0 ?        Z    07:34   0:00 [chromium-browse] defunct

manu      3435  0.0  0.0      0     0 ?        Z    07:44   0:19 [chromium-browse] defunct

manu      3722  0.0  0.0      0     0 ?        Z    08:21   0:00 [pidgin] defunct

manu      4287  0.1  0.0      0     0 ?        Z    09:26   0:38 [chromium-browse] defunct

manu      5378  0.1  0.0      0     0 ?        Z    11:24   0:15 [chromium-browse] defunct

 

# ps aux |grep Z

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

manu      3366  0.0  0.0      0     0 ?        Z    07:34   0:00 [chromium-browse]

manu      3435  0.0  0.0      0     0 ?        Z    07:44   0:19 [chromium-browse]

manu      3722  0.0  0.0      0     0 ?        Z    08:21   0:00 [pidgin]

manu      4287  0.1  0.0      0     0 ?        Z    09:26   0:38 [chromium-browse]

manu      5378  0.1  0.0      0     0 ?        Z    11:24   0:15 [chromium-browse]

 

To know how many Zombie processes running on the server?

To get a count of all the Zombie processes on the server. This can be done in different ways.

Please see the commands to run to fetch out the number of Zombie processes.

# ps aux | awk {‘print $8’}|grep -c Z

7

or

# ps aux | awk ‘{ print $8 ” ” $2 }’ | grep -wc Z

7

or

# ps aux | awk {‘print $8’}|grep Z|wc -l

7

 

After this, we need to list the process ID or PID of the Zombies. To list the PID of the Zombies that are running on the server at the moment, run the below command from the terminal as the root user.

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

Now you will get an output as follows.

Z 3366

Z 3435

Z 3722

Z 4287

Z 5378

 

In order to kill these zombie processes, you need to find out the parent process ID first.

To find the parent processes run the below command.

# pstree -paul

 

Now you will get an output as given below.

[root@vps ~]# pstree -paul

init,1

|-crond,542

|-dovecot,6576

|   |-anvil,6577,dovecot

|   |-config,25099

|   `-log,6578

|-httpd,5047

|   |-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

|-(kthreadd/3929,2)

|   `-(khelper/3929,3)

|-master,5227

…..…

 

From this, we can easily find out the PID of the parent of the zombie process.  The next thing is to kill them or need to restart the services.

To kill the processes, run following the command

[root@server]# kill -9 PID

 

If you need any further help, please do reach our support department.

 

Leave a Reply