How to check and kill zombie processes in Debian 10

 

 

 

The term “zombie process” refers to a process that has been executed, but it has not yet been terminated but is in a “Terminated” state in Unix-based or Unix-like operating systems. As a result of the parent process reading the results of the child process, child processes often exhibit zombie behavior. So in this article, we will show you how to find and kill zombie processes on Debian 10.

 

 

 

 

  

Step 1: How to determine whether a zombie process is running in Debian 10

 

 

 

 

 

You can use the top command to see which processes are active on your system. Run the following command in the terminal

 

 

 

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

 

 

Upon discovering zombie processes, you can immediately proceed to step 3 to terminate them. When none are present, we will create a dummy zombie process and terminate it as an experiment.

 

 

 

 

 

 

 

Step 2: Creating a dummy zombie process in Debian 10

 

 

 

 

 

 

The following code should be pasted into a text editor. This code was copied from vitux.com.

 

 

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>int main ()
{
pid_t child_pid;child_pid = fork ();
if (child_pid > 0) {
sleep (60);
}
else {
exit (0);
}
return 0;
}

 

 

 

Specify zombie.c as the file name. In this code, a zombie process is created for 60 seconds. A time parameter (in seconds) can be specified in the sleep() function to increase the time duration.

 

 

 

 

 

Compile this program by running the following command:

 

 

cc zombie.c -o zombie

 

 

 

 

Create a zombie process which will be active for sixty seconds by running the following command.

 

 

./zombie

 

 

 

 

 

 

Step 3: Getting rid of zombies

 

 

 

 

 

 

To find out the ID of the zombie parent process, run the following command in the Terminal. Please note the Parent ID “pid” from the output of the following command. Which will be the First 

 

 

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

 

 

 

Our previous creation of the zombie should be shown to you. Copy the parent process ID from the result (which will be the 2nd entry in the command result) and run the below command to kill the zombie.

 

 

# kill -9 <Parent process ID>

 

 

 

 

 

 

Thanks for reading! I hope it was informative for you! 







Try VPSie for free today!