How to create a Dummy Zombie Process in the C programming language in Debian 10

A zombie process is a type of process that has been completed, but whose record still remains in the process table due to the lack of communication between the child and parent processes. The small program developed in this guide may be useful for educational purposes. For instance. when it comes to detecting zombie processes under Linux.

In this tutorial, I will create a dummy zombie process in Debian 10.

Creating a dummy zombie process in Debian 10

Open notepad and paste the following code.

#include 
#include 
#include 
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.cThe zombie process created using this code will run for 120 seconds. You can set the duration (in seconds) in standby mode.

Then open a terminal and run the following command to compile the code above.

cc zombie.c -o zombie

After this command, an executable target file must be created in your current directory.

Run the zombie file:

./zombie

When you run the following command with grep, you will get the parent id of the zombie process.

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

So, here is how you create a fictitious zombie process in Debian 10. I hope you have no difficulty completing this tutorial.

How to create a Dummy Zombie Process in the C programming language in Debian 10

Sidebar