Question
A process executes the code
fork();
fork();
fork();
The total number of child processes created is
Official answer and solution
- Official answer
- C
- From
- Official GATE 2012 answer key
Solution
Determine the total number of processes created by n successive fork calls and subtract the initial parent process.
Each call to fork() duplicates all existing processes:
- Initially, there is 1 parent process.
- After the first
fork(), the number of processes doubles to . - After the second
fork(), the number of processes doubles to . - After the third
fork(), the number of processes doubles to .
Among these 8 total processes, 1 is the original parent process, and the remaining are newly created child processes:
Thus, 7 child processes are created, which matches option (C).
C
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2012 Computer Science and Information Technology (CS)
- Question
- 8 of 65, printed as CS Q.8
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.