How to create a dummy zombie process in the C programming language on Debian 10

s2 0

A zombie process is a type of process that has completed, but whose entry still remains in the process table due to a lack of communication between the child and parent process. The small program developed in this tutorial can be useful for learning purposes. For example, when it comes to the detection of zombie processes under Linux.

In this tutorial I am going to create a dummy zombie process in Debian 10.

Creating a dummy zombie process in Debian 10

Open the notepad and paste the following code.

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

Save this file as zombie.c. The zombie process created with this code will run for 120 seconds. You can adjust the duration (in seconds) in the sleep function.

Next, open Terminal and run the following command to compile the code above.

cc zombie.c -o zombie

After this command, a target executable file should have been created in your current directory.

Run the zombie file:

./zombie

Running the following command with grep will give you the parent ID of the zombie process.

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

So here’s how to create a dummy zombie process in Debian 10. Hope you have no trouble following this tutorial.

How to create a dummy zombie process in the C programming language on Debian 10