What is zombie process on Linux

Everything running on a Linux system is a process, either taking place in the foreground (visible to the user) or in the background (unapparent processes like system services). There are various states that a process can be in, those being running, uninterruptable sleep, interruptable sleep, stopped, and zombie. But what is a zombie process?

In this tutorial, we will discuss zombie processes on Linux. We will go over their definition, their purpose, and how to identify and get rid of them on a Linux system.

In this tutorial you will learn:

  • What is a zombie process and why do they exist?
  • How to identify zombie processes
  • How to kill a zombie process
What is zombie process on Linux
What is zombie process on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software ps, kill
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

What is a zombie process?




As mentioned above, a Linux process can be in several different states. The one we are concerned with is a zombie process. A zombie process is a process that has completed execution – either gracefully or forcefully closed. The process is dead (hence the name) yet still exists in the process table. It simply has not been cleared away yet, but it is no longer running. It is a dead process that has yet to go away completely, kind of like… a zombie!

NOTE
A zombie process is also sometimes called a defunct process. A process enters the zombie state when it receives a SIGCHLD signal.

A zombie waits for its parent process to read its exit value via wait() or waitpid(), and then it will be cleared off the process table. If the parent process exits, then init will destroy its leftover zombies.

Identify and kill zombie processes

There are not many good ways to easily identify zombie processes. It is not something that a user typically needs to concern themselves with, as the system is perfectly capable of managing the zombie processes. The only exception might be a buggy program that continually spawns child processes and never clears them properly.

Still, if you are determined to look for zombie processes, we can use the ps command. Use the following options to filter out the PID and status column. We will then pipe to awk in order to show only the processes with a status of ‘Z’ (zombie).

$ ps axo pid=,stat= | awk '$2~/^Z/ { print }'

Once again, it is not typically necessary to identify these processes, much less kill them. However, a simple kill command will do the trick. Just supply the PID retrieved earlier as an argument to the command.

$ kill 1234

If it does not work, you can send a SIGKILL signal by using the -9 option with your command:

$ kill -9 1234

Closing Thoughts




In this tutorial, we learned what a zombie process is on a Linux system. We also saw how to identify the zombie processes on our own system, and manually destroy them. The zombie state is just one of five possible states that a process can be in – all with their own important purpose.



Comments and Discussions
Linux Forum