How to Kill Zombie Processes in Ubuntu

Wondering how to kill zombie processes in Ubuntu? We got you covered!

Processes refer to any program that is running on an operating system. These programs are executed on the system and can be either inactive or active in the foreground.

While most processes that are running in the background are needed for a successful working operating system, unwanted processes can also start up over time.

These unwanted processes can take up resources, eventually slowing down your system. Zombie processes are a prime example.

This guide will teach you how to kill zombie processes in Ubuntu. We’ll go over the basics of a zombie process, and methods to get rid of them.

So without further ado, let’s begin!


What are Zombie Processes?

Processes can be categorized into parent and child. Parent processes refer to those that are responsible for creating multiple processes, whereas child processes are those that are created by another process.

Each parent is linked to their respective child process. When these child processes are terminated, the parent gets the information and proceeds to free up any used resources like disk, RAM, etc.

However, there are cases where the parent process is uninformed that its child process has been terminated. Such processes are referred to as “zombie processes” and continue to use the system’s resources despite being terminated.

Although their effect is not noticeable at first, especially if you’re running a system with limited resources like RAM, the overall system will eventually slow down, and even the mainstream processes will be prone to crashing.


Identifying a Zombie Process.

Identifying a zombie process is easy on Linux distributions because of the flags that govern process states.

Most Linux distributions represent the process state using the following flags:

  • D Refers to a process uninterrupted while sleeping.
  • I Refers to any idle processes.
  • R Refers to any processes that are currently running on the system.
  • S Refers to any processes that are currently in sleep mode on the system.
  • T Refers to processes stopped by a signal issued via job control.
  • t Refers to processes stopped during a trace via the debugger.
  • Z Refers to zombie processes.

These processes can easily be identified in the Terminal with the help of the $top command.

We’ll be using Ubuntu 20.04 LTS to demonstrate command executions in this guide. However, the process should be different for other versions of Ubuntu, either.

Follow these steps to use the $top command in Linux:

  1. Start by opening the Command Terminal. The shortcut is Ctrl + Alt + T.
  2. Once the Terminal is open, type the following command:
$ top
kill zombie processes in ubuntu

This will display all the processes that are running on the system. By going through the list of processes, you should be able to identify zombie processes on your system.

If you did these steps correctly, then you’ve learned how to identify zombie processes successfully. All that’s left to do is to learn how to kill them.


Killing Zombie Processes in Ubuntu.

Now that you have learned how to identify a zombie process, you can proceed to kill them.

Zombie processes can directly be terminated with the help of the Command Terminal.

To begin, list all the zombie processes that are running on your system. We do this to find their corresponding process IDs (PID). Follow these steps to list all zombie processes:

  1. First, open the Command Terminal by pressing Ctrl + Alt + T on your keyboard.
  2. Once that’s done, type the following command:
$ ps aux | awk '$8 ~ /^[Zz]/'
kill zombie processes in ubuntu

This will display all the zombie processes on your system.

Once that’s done, you will need to find the parent process since it’s needed to eliminate these child processes. Follow these steps to identify a parent process.

  1. Start by opening the Command Terminal
  2. Next, type the following to list the parent process of the child:
$ ps -o ppid= -p <process ID of child>

Instead, you can find both the process IDs of the zombie and parent process by typing the following in the Command Terminal:

$ ps -A -ostat,pid,ppid | grep -e '[zZ]'

Once you identify the ID of the parent process, proceed to kill it using the kill command. Follow these steps to use the kill command and terminate the parent process:

  1. Begin by opening the Command Terminal by pressing Ctrl + Alt + T on your keyboard.
  2. Once the Terminal is open, type in the following:
$ kill -9 <parent process ID>

This will terminate the parent process. You can use the following command to see if the zombie processes are still longer running on your system.

$ top
kill zombie processes in ubuntu

If you followed the steps correctly, then congratulations, you’ve successfully learned how to kill zombie processes in Ubuntu.


Additional Information.

If you’re looking to kill all the child processes that are linked to the parent, you can use the $ killall command.

The $ killall command removes all instances of a process that share the same name.

Follow these steps to use the $ killall command:

  1. Start by opening the Command Terminal. The shortcut is Ctrl + Alt + T.
  2. Once the Terminal is open, type the following command:
$ killall <name of program>

Unwanted processes are often the result of installing additional programs that continue to run in the background at startup. These programs can end up taking a lot of resources without being of any use. Here are some tips for how you can deal with these processes.

  • Prevent unwanted programs from running at startup.
  • Uninstall unwanted programs from your system.
  • Kill any unneeded processes at startup.

If you follow these steps, you won’t be facing any issues regarding your system slowing down.

The $ kill command can also be used with different flags and identifiers. These flags change the way the kill command works. Knowing how to use the kill command will save you time and will aid you in learning how to kill a process in Linux.

This concludes our guide on how to kill zombie processes in Ubuntu. We went over the basics of a zombie process, how to identify them, and lastly, how to terminate them with the help of the Command Terminal. If you have any questions or suggestions, let us know in the comment section down below.

If this guide helped you, please share it. 🙂

Author

Leave a Reply

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