How to create Zombie process using C code manually ?
Today we will see an example how to create a zombie process on our linux machine using a short c program.
For this, we will open two terminal sessions.
On First Terminal
1. Create a C file with following code.
### Here we create a new process and then sleep it. ### As a result the parent process becomes zombie. [root@ngelinux ~]# cat abc.c #include#include #include int main () { pid_t newpid; newpid = fork (); if (newpid > 0) { sleep (80); } else { exit (0); } return 0; } [root@ngelinux ~]#
2. Compile the code and create object file
[root@ngelinux ~]# gcc -o abc.o abc.c [root@ngelinux ~]#
3. Run the executable object file
[root@ngelinux ~]# ./abc.o
On Second Terminal
Since the program is executed, we can now see the zombie process in the process list.
[root@ngelinux ~]# ps -e -o pid,ppid,stat,cmd | grep Z 2123 2121 Z+ [abc.o]2126 1847 S+ grep Z [root@ngelinux ~]#