Zombie Process using C Programming Language - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Zombie Process using C Programming Language

Share This

A zombie process is one that has completed execution but still has an entry in the process table to report to its parent process.

A child process is never deleted from the process table without first turning into a zombie. The exit status of the child process, which removes the child process entry from the process table, is read by the parent process.

While the parent in the following code sleeps for 50 seconds without calling wait(), the child completes its execution via the exit() system call, and the child's entry in the process table is still present.

Code for Zombie Process
#include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> int main () { pid_t c_pid; printf("variable c_pid: %d\n", c_pid); c_pid = fork(); printf("start: %d\n", c_pid); if (c_pid > 0) { printf("parent before sleep: %d\n", c_pid); sleep (50); printf("parent after sleep: %d\n", c_pid); } else { printf("child: %d\n", c_pid); sleep (20); exit (0); } printf("end: %d\n", c_pid); return 0; }

During execution of the program, we have continiously checked the list of running processes. The following results show that the child process became zombie process after 10 seconds.

Happy Exploring!

No comments:

Post a Comment