Search
Close this search box.

How to check and kill zombie processes in Debian 10

Table of Contents

How to check and kill zombie processes in Debian 10

 

Zombie processes are a common issue that can occur in the Debian operating system, as well as other Unix-based systems. Zombie processes are processes that have completed their execution but still have an entry in the process table. These processes can accumulate over time and cause issues with system performance and stability.

 

When a process is executed, it is assigned a process ID (PID) and a parent process ID (PPID). When the process completes its execution, it sends a signal to its parent process to indicate its status. The parent process then collects the status of the child process using the wait() system call.

 

If the parent process fails to collect the status of the child process, the child process becomes a zombie process.

 

Zombie processes are not actively running, but they still occupy system resources such as memory and CPU time. They can accumulate over time and cause issues with system performance and stability. One of the most common symptoms of a system with a large number of zombie processes is sluggish performance,

 

as the system becomes overloaded with processes that are not actively doing anything.

 

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 
#include <sys/types.h>
#include 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 that 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 

 

In conclusion, zombie processes are a common issue that can occur in the Debian operating system and other Unix-based systems. They can accumulate over time and cause issues with system performance and stability. Checking for and killing zombie processes in Debian requires the use of the

 

ps and kill

 

commands, while preventing zombie processes requires proper handling of the exit status of child processes in code and regular monitoring of the system for zombie processes.

 

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

 

Install Zikula on Ubuntu

Zombie processes are dead processes that have completed their execution but still have an entry in the process table. They occur when a child process dies before the parent process has had a chance to collect its status.

You can use the ps command to check for zombie processes. Run the command ps aux | grep Z to display all processes with a status of “Z”, which indicates a zombie process.

Zombie processes cannot be killed like regular processes, as they are already dead. However, you can remove their entries from the process table by killing the parent process. Identify the parent process of the zombie process using the ps command, and then use the kill command to terminate the parent process. This will cause the zombie process to be removed from the process table.

If you cannot kill the parent process of a zombie process, you may need to reboot the system to remove the zombie process from the process table. Before rebooting, make sure to save any unsaved work and close all running applications to prevent data loss.

To prevent zombie processes from occurring, make sure to properly handle the exit status of child processes in your code. You can use the wait() system call to collect the status of a child process and prevent it from becoming a zombie process. Additionally, regularly monitoring your system for zombie processes and addressing them promptly can help prevent them from accumulating and causing system issues.

Make a Comment
Share on
Facebook
Twitter
LinkedIn
Print
VPSie Cloud service

Fast and Secure Cloud VPS Service

Try FREE
For a month

The First 1 orders gets free discount today! Try Sign up on VPSie to get a chance to get the discount.