fork() system call is used to create a process generally known as child process and the process that created it is known as parent process. Now, all the processes that are created using fork() runs concurrently. But what if we want the last process created to execute first and in this manner bottom to up execution such that parent process executes last.
This can be done by using wait() system call. The parent process may then issue a wait() system call, which suspends the execution of the parent process while the child executes and when the child finishes execution, it returns exit status to operating system. Now wait() suspend the process until any of its child process finish execution.
NOTE: This is a linux system call, so it must be executed on linux or unix variant system.
Grand Child Terminated 2nd Child Terminated 1st child Terminated Parent Terminated
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.
- fork() and memory shared b/w processes created using it
- Wait System Call in C
- Execute both if and else statements in C/C++ simultaneously
- Conditional wait and signal in multi-threading
- How to execute zombie and orphan process in a single program?
- Zombie Processes and their Prevention
- Zombie and Orphan Processes in C
- Chat application between two processes using signals and shared memory
- fork() in C
- Fork CPP | Course Structure
- searching in fork()
- sorting in fork()
- C vs BASH Fork bomb
- fork() and Binary Tree
- Fork() - Practice questions
- Difference between fork() and exec()
- C program to demonstrate fork() and pipe()
- Factorial calculation using fork() in C for Linux
- Creating multiple process using fork()
- Calculation in parent and child process using fork()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.