Question

A process executes the code

fork();
fork();
fork();

The total number of child processes created is

Choose one option
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 21=22^1 = 2.
  • After the second fork(), the number of processes doubles to 22=42^2 = 4.
  • After the third fork(), the number of processes doubles to 23=82^3 = 8.

Among these 8 total processes, 1 is the original parent process, and the remaining are newly created child processes:

Total child processes=23−1=8−1=7\text{Total child processes} = 2^3 - 1 = 8 - 1 = 7

Thus, 7 child processes are created, which matches option (C).

Final answer

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.