How to create a dummy zombie process in Ubuntu 18.04 LTS

As software testers, we sometimes need to know what the zombie process looks like on our system. We can run various tests if we know exactly which program and process identifier is associated with this zombie process.

What is a zombie process?

A zombie or non-existent process on Linux is a process that has been completed, but its record still remains in the process table due to the lack of correspondence between the parent and child processes. Typically, the parent process checks the status of its child processes using the wait () function. When the child process is completed, the wait function informs the parent about the complete exit of the process from memory. However, if the parent cannot call the wait function for any of its child processes, the child process remains alive in the system as a dead or zombie process. These zombie processes can accumulate in large quantities in your system and affect its performance.

When you run the top command and the zombie works, it will be indicated in the second line of output as follows:

The zombie process is shown in the top command.

However, if the zombie process is not running on your system, you can create a dummy for testing, as described in this article. We run this process on Ubuntu 18.04.

Create a zombie process

In this section, we will write program c to start the zombie process on our system.

Open a text editor and enter the following code:

The code

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

Save this file as zombie.c

The zombie process created using this code will run for 60 seconds. You can increase the duration by specifying the time (in seconds) in the sleep () function.

Open a Terminal and run the following command to compile this program:

$ cc zombie.c -o zombie

An executable file named zombies will now be created. Advertising

Note that you will need to install the GNU C compiler, if it is not already installed on your system, using the following command:

$ sudo apt-get install build-essential

Now run the zombie program with the following command:

./zombie

You will see the following output:

Zombie File Output

You can use the parent process identifier (PPID) and child process identifier (PID) during testing; for example, killing this zombie process with the kill command.

While this process is running, you can view the system performance in another terminal window using the top command. You can see 1 zombie process through the second line of output.

The ps command will now also show this non-existent process and the zombie program responsible for it:

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

Ps command result

This command will give you the state, parentID, process ID, the program that starts the zombie process (the zombie program that we launched in this tutorial).

Now you have learned how to create a simple dummy zombie process. This will give you an idea of ​​how it looks on your system and how you can use it for testing.

How to create a dummy zombie process in Ubuntu 18.04 LTS

Sidebar