How to find and kill zombie processes on your Linux data center servers

Zombied processes can indicate a software problem. So when a process goes full-on zombie, you need to know what to do.

How to find and kill zombie processes on your Linux data center servers Zombied processes can indicate a problem with a piece of software. Jack Wallen shows you how to find and kill those zombies on your Linux data center servers.

Braaaaains.

Wait. Wrong type of zombies.

CPUUUU cycllllles.

Nope.

PIIIIIIIDS.

More like it.

Every so often a Linux process goes astray and does nothing—not even gobble up CPU cycles. Although zombies don't use precious resources (like a running and rogue app might), it can pose a threat. How? When a process is zombied, it retains its Process ID (PID). Since Linux systems have a finite number of PIDs (although that number is pretty high), should enough PIDs be zombied, no other process could launch.

SEE: Disaster recovery and business continuity plan (Tech Pro Research)

Chances of that happening are very unlikely. However, more importantly, zombied processes indicate something has gone wrong with an application, and there might be a bug in a particular program. Bugs on data center software should not be tolerated and need to be addressed. Until the flaw is addressed, you might want to check for and kill zombie processes.

So when a process goes full-on zombie, what do you do? You find and kill those zombie processes. Let me show you how.

Finding a zombie

The first thing to do is to find the zombie process. Fortunately, this is really easy, thanks to the ps command. Pipe the output of the ps command through grep to list out any process whose STAT is Z (for zombie). Open a terminal window and issue the following command:

ps aux | grep 'Z'

The output of the above command will list out any process that includes Z in the output (Figure A).

Figure A

Figure A: Plenty of Zombied commands.

As you can see, there are a number of running processes that have a Zombie status. This command will also list any process that includes the letter Z in the output, so you need to ignore anything without a Z in the STAT column.

Killing a zombie

Instead of decapitating, burning, or completely dismembering the zombie, we want to use the kill command to end those zombies. The output of the first command will include the PID of all zombied processes, so to kill one of those, you issue the command:

kill PID

Where PID is the process ID of the process in question. So if you want to kill the zombied thunderbird process (with PID 20589), the command is:

kill 20589

And that's it.

You could get crafty and cobble together a bash script to take care of this automatically, however, you run the risk of killing a necessary process. Because of that risk, I always recommend taking care of this task manually. This is especially true, considering we're working with a production-level, data center server (although I demonstrated on a desktop machine).

If you find services and apps crashing on you, you should check for zombied processes and get rid of them. Once you know which processes are being zombied, file a bug report or contact the developer and let them know (especially if this becomes a regular occurrence for an application).

Also see

Image: Jack Wallen