How to kill zombie processes in Linux

zombie processes

How will you know the zombie processes or dead in Linux are processes that have been completed, but still appear in the process table due to a parent-child process mismatch. The parent process controls the state of the child processes using the function wait(), and when the child terminates, that function tells the parent to kill the process from memory.

However, if the parent process fails to call such a function for any of its child processes, those child processes will be left "alive" and occupying system resources that could be used by other processes, affecting performance. That's why it's important to do kills from time to time to kill all those zombie processes. To do this, two ways can be highlighted: by GUI or by the terminal:

through the terminal

zombie processes

To kill zombie processes in Linux, you must first identify what those processes are and then kill them. Well, this could be done with tools like ps, top, etc. You can use the one you like the most. For example, here are two of the commands you could use to detect if there are zombie processes:

top

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

In the first case, it is an interactive command that shows you the processes and will show you on the second line (as you can see in the image) the number of zombie processes that there are right now (in this image 11). In addition, you can scroll through the list of processes, and in the S column you can see the status. If it's marked Z, then it's a zombie.

In the second case, it will simply show you an output with the zombie processes you have running.

It is important, both in one case and in the other, to pay attention to the PID of the zombie processes to kill them with:

sudo kill -9 PID

You replace PID by the process number in your case. Also, if it doesn't work, you probably need privileges, so you'll have to use sudo in front of the command...

Through the GUI

system monitor, processes

You can also do it using graphical tools, if you don't have much dexterity with the terminal and commands. For example, you can use system monitors, such as System Monitor or the like. And here too you have to locate the zombie processes first and then kill them:

  1. Open System Monitor.
  2. Go to the Processes tab.
  3. Now, using the search tool (magnifying glass), search for the term zombie.
  4. In the processes that appear in the list, click on them with the right mouse button and press Kill.

It is important that you make sure that it is showing all processes of the system. To check this, go to the System Monitor settings menu and look at the options that are checked.


The content of the article adheres to our principles of editorial ethics. To report an error click here.

Be the first to comment

Leave a Comment

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

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.