Zombie and Orphan Processes in C Last Updated : 19 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Prerequisite: fork() in C Zombie Process: A process which has finished the execution but still has entry in the process table to report to its parent process is known as a zombie process. A child process always first becomes a zombie before being removed from the process table. The parent process reads the exit status of the child process which reaps off the child process entry from the process table. In the following code, the child finishes its execution using exit() system call while the parent sleeps for 50 seconds, hence doesn’t call wait() and the child process’s entry still exists in the process table. C // A C program to demonstrate Zombie Process. // Child becomes Zombie as parent is sleeping // when child process exits. #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main() { // Fork returns process id // in parent process pid_t child_pid = fork(); // Parent process if (child_pid > 0) sleep(50); // Child process else exit(0); return 0; } Note that the above code may not work with online compiler as fork() is disabled. Orphan Process: A process whose parent process no more exists i.e. either finished or terminated without waiting for its child process to terminate is called an orphan process. In the following code, parent finishes execution and exits while the child process is still executing and is called an orphan process now. However, the orphan process is soon adopted by init process, once its parent process dies. C // A C program to demonstrate Orphan Process. // Parent process finishes execution while the // child process is running. The child process // becomes orphan. #include<stdio.h> #include <sys/types.h> #include <unistd.h> int main() { // Create a child process int pid = fork(); if (pid > 0) printf("in parent process"); // Note that pid is 0 in child process // and negative if fork() fails else if (pid == 0) { sleep(30); printf("in child process"); } return 0; } Note that the above code may not work with online compilers as fork() is disabled. Related : Any idea What are Zombies in Operating System? Zombie Processes and their Prevention Comment More infoAdvertise with us Next Article Maximum number of Zombie process a system can handle K kartik Improve Article Tags : C Language system-programming CPP-Library Similar Reads Zombie Processes and their Prevention A zombie process is a process that has completed its execution but still remains in the process table because its parent process has not yet read its exit status. It is called a "zombie" because it is no longer active or running, but it still exists as a placeholder in the system. Zombie processes d 7 min read How to execute zombie and orphan process in a single program? Prerequisite: Zombie and Orphan Processes in C Zombie Process: A zombie process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the parent process to read its child's exit status. A process that terminates cannot leave the sy 2 min read Double forking to prevent Zombie process We have discussed Three methods of Zombie Prevention. This article is about one more method of zombie prevention. Zombie Process: A process which has finished the execution but still has entry in the process table to report to its parent process is known as a zombie process. A child process always f 2 min read Maximum number of Zombie process a system can handle Zombie Process or Defunct Process are those Process which has completed their execution by exit() system call but still has an entry in Process Table. It is a process in terminated state. When child process is created in UNIX using fork() system call, then if somehow parent process were not availabl 2 min read Calculation in parent and child process using fork() Write a program to find sum of even numbers in parent process and sum of odd numbers in child process. Examples: Input : 1, 2, 3, 4, 5 Output : Parent process Sum of even no. is 6 Child process Sum of odd no. is 9 Explanation: Here, we had used fork() function to create two processes one child and o 2 min read Creating child process using fork() in Python Create a child process and display process id of both parent and child process. Fork system call use for creates a new process, which is called child process, which runs concurrently with process (which process called system call fork) and this process is called parent process. After a new child pro 2 min read Like