How to kill Ubuntu Zombie Process

A zombie or a defunct process in Linux is a process that has been completed, but its entry still remains in the process table due to lack of correspondence between the parent and child processes. Usually, a parent process keeps a check on the status of its child processes through the wait() function. When the child process has finished, the wait function signals the parent to completely exit the process from the memory. However, if the parent fails to call the wait function for any of its children, the child process remains alive in the system as a dead or zombie process. These zombie processes might accumulate, in large numbers, on your system and affect its performance. In that case, you might have to kill these zombies manually through the ways and commands described in this tutorial.

Viewing Zombie Processes

You can have a check on your system performance by viewing the various processes running on your system, including the efficiency altering zombie processes. Ubuntu allows you to view these processes in the following manner:

  • Through the Graphical User Interface
  • Through the Command Line

Through the GUI

In order to graphically view any zombie processes running on your system, open the System Monitor utility through your Ubuntu Dash. In the following screenshot of my System Monitor, you can view that there are two zombies running on my system. It is also possible that the number of zombie processes on your system might be less or more than the ones running on mine.

View Zombie Processes in GUI

Through the Command Line

The top command displays a detailed view of the processes running on your system along with the memory and CPU resources they are using. It also gives you information about any zombie processes running on your system. Open the Terminal by pressing Ctrl+Alt+T and then type top. I got the following output after running this command.

$ top

Find Zombie Processes on the command line

You can see in the second line that there is 1 zombie process running on my system.

If you want further details about the zombie process, use the following command:

$ ps axo stat,ppid,pid,comm | grep -w defunct

Get details about a zombie process on Linux

This command will give you the state, parentID, the process ID, the program that is running the zombie process(a dummy program by the name ‘zombie’ on my system). The defunct flag tells you that this is a dead, zombie process.

Killing a Zombie-Process

First, let us understand how zombie processes are a threat to our system’s performance. It is important to learn that zombies are dead and mostly completed processes that do not take memory or CPU resources. However, each of these processes has a unique process ID assigned to them which comes from a limited pool of PIDs reserved for your processor. If a large number of zombies gather, they will eat up most part of the PID pool and the new processes will not be able to launch due to lack of a process ID.

A small number of defunct programs occupying your system is not a big threat but that means that their parent programs have not been able to call them off due to a bug or a missing wait() function.

When a parent process has not been able to call the wait() function automatically, we need to manually signal the parent process to run the wait function on all its children so the ones with a complete state can be called back. We can do this by running the SIGCHLD command. When that doesn’t work, we can manually kill the parent process so that all its zombie children are also killed, freeing the process IDs for the new processes.

You can kill the zombie processes through the following ways:

  • Through the Graphical User Interface
  • Through the Command Line

Through the GUI

You can kill a zombie process graphically through the System Monitor Utility as follows:

  1. Open the System Monitor utility through Ubuntu Dash.
  2. Search for the term Zombie through the Search button.

How to kill a zombie process on Linux desktop

The zombie process will be killed from your system.

Through the Command Line

After you know that there any zombie processes running on your system through the top command, view the details of the processes.

The usual way is to use the following command that signals the zombie’s parent process to kill the command.

$ kill -s SIGCHLD PID

This command may not work in a few cases as not all parent processes are programmed properly in order check upon the child processes. In that case, you can kill the parent process through the following command:

$ sudo kill -9 3376

Kill a zombie process on the commandline

When you have killed all the zombie processes through this way and run the top command, you will be able to see that there are no zombie processes running on your system anymore:

Zombie process killed

After working along with this tutorial, you can optimize your operating system by looking for any zombie processes on your system and killing them manually through the command line or the graphical user interface. This act will free up process IDs for the new processes that you want to run on your system.

How to Kill Zombie Processes in Ubuntu 18.04 LTS