Linux processes often go astray, do nothing, or even consume CPU cycles. Although zombie processes do not occupy valuable resources like running rogue applications, they may pose a threat. How does it pose a threat? When a process becomes a zombie process, it retains its process ID (PID). Because the number of PIDs in Linux system is limited (but large), if enough PIDs become zombies, other processes cannot start.

The probability of this happening is very small. More importantly, however, the zombie process indicates that there is something wrong with the application, and there may be an error in a program. Errors in data center software should not be tolerated and need to be addressed. You may need to check and kill the zombie process to solve the problem.

So what do you do when a process becomes a zombie process? You have to find and kill those zombie processes. Here’s how to do it.

Find the zombie process

The first thing to do is to find out the zombie process. Fortunately, thanks to the PS command, this is simple. Grep displays the output of the PS command and lists any processes where stat is Z (for zombies). Open the terminal window and execute the following commands:

ps aux

grep “Z”

The output of the above command lists any processes with Z in the output (figure a).

How to correctly handle the zombie process on the Linux Data Center Server

Figure a

As you can see, many running processes are zombie. This command will also list any processes with the letter Z in the output, so you want to ignore any processes without Z in the stat column.

Kill zombie process

We want to use the kill command to end those zombie processes. The output of the first command will include the PID of all zombie processes, so if you want to terminate one of them, just execute the command:

kill PID

Where PID is the process ID of the related process. Therefore, if you want to end the Thunderbird process that has become a zombie (its PID is 20589), the command is:

kill 20589

this is it.

You can write a bash script to automatically handle this task, but it may kill the necessary processes. Because of this risk, I always recommend that you handle this task manually. This is especially true considering that we are facing production data center servers (although I demonstrated it on the desktop system).

If you find that services and Applications Crash, you should check for zombie processes and terminate them. Once you know which processes are zombies, submit an error report or contact and inform the developer (especially if the application crashes often).

Source: 51CTO


Leave a Reply

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