How to check and kill zombie processes in Debian 10

A zombie process is a type of process that is completed, but its record still remains in the process table due to the lack of communication between the child and parent processes.

In this guide, I am going to demonstrate how you can test and kill the zombie process in Debian 10.

necessary condition

You must have superuser rights and at least one zombie process entry in the process table.

How to check the zombie process in Debian 10

Via command line

You can get a list of all processes running on your system using the top command, as shown below.

To check the zombie process on your Debian 10 computer, you need to open a terminal and run the following command.

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

List of zombie processes using the PS command

Since we have no zombie process running on our machine. Therefore, in the next step, we will create a fictitious zombie process so that I can kill it. If the zombie process were running, the team would return its PID, etc.

Via graphical interface

The same can be done using the graphical interface. Open system monitor utility from the dashboard as shown below.

system monitor utility

The tool will show you a list of all processes running on your computer. You can also scroll up and down to see all the processes.

Find zombie processes in the system monitor

How to create a fictitious zombie process in Debian 10

Open a text editor and paste the following code. The code was copied from https://vitux.com/how-to-create-a-dummy-zombie-process-in-ubuntu/

#include 
#include 
#include int main ()
{
pid_t child_pid;child_pid = fork ();
if (child_pid > 0) {
sleep (60);
}
else {
exit (0);
}
return 0;
}

Save the file as zombie.c. The zombie process will run for 60 seconds. However, you can set the time in sleep mode.

Then open a terminal and run the following command to compile this program. This will create the target executable.

cc zombie.c -o zombie

Then run the following command to create a zombie process that will be alive for sixty seconds.

./zombie

Dummy zombie process

How to kill a zombie process

Via command line

We now have a zombie process, so we can also kill it.

Open a terminal and run the following command to find out the identifier of the parent zombie process.

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

The following screenshot shows that the parent process ID is the second record as a result of the command.

Kill zombie process

Run the following command on a terminal with root privileges and this will kill the zombie process.

kill -9  (which is 2844 in our case)

If you check processes using the ps command, you will not notice a single zombie or non-existent process running on your system.

Via graphical interface

Open the system monitor utility again on the toolbar and list the processes of all users. You will notice one zombie process running on your computer.

Kill the zombie process in the Debian GUI

Now right-click the zombie process and click the kill button to kill the process. You will be asked to confirm. Click “Kill Process” to confirm. You will also be prompted for the root credentials.

I hope this tutorial has helped you a lot in understanding zombie processes.

How to check and kill zombie processes in Debian 10

Sidebar