Prerequisite: fork() in C
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.
Note that the above code may not work with online compiler as fork() is disabled.
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.
Note that the above code may not work with online compilers as fork() is disabled.
This article is contributed by Pranjal Mathur.If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to execute zombie and orphan process in a single program?
- Zombie Processes and their Prevention
- Double forking to prevent Zombie process
- fork() and memory shared b/w processes created using it
- Chat application between two processes using signals and shared memory
- fork() to execute processes from bottom to up using wait()
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- INT_MAX and INT_MIN in C/C++ and Applications
- fesetround() and fegetround() in C++ and their application
- Queries to insert, delete one occurrence of a number and print the least and most frequent element
- Get first and last elements from Array and Vector in CPP
- Similarities and Differences between Ruby and C++
- Generate an array of given size with equal count and sum of odd and even numbers
- Similarities and Difference between Java and C++
- Comma in C and C++
- How does "void *" differ in C and C++?
- What are the operators that can be and cannot be overloaded in C++?
- Data type of character constants in C and C++
- Can we use function on left side of an expression in C and C++?
- delete and free() in C++