GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 66

Process count after repeated fork

Operating Systems · Processes, Threads & System Calls · Full GATE CSE 2008 paper

GATE 2008, Q66 2 marks · MCQ
Report issue

Processes, Threads & System Calls

Question 66, GATE 2008: A process executes for(i=0;i<n;i++) fork();. How many child processes are created in total, assuming all forks succeed?

(A) n
(B) 2^n−1
(C) 2^n
(D) 2^(n+1)−1
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step through it (3 cases)

1. Both parent and new child continue the loop after each successful fork. Hence each iteration doubles the number of processes still executing.
2. From one process, n iterations yield 2n total processes. Equivalently the iterations create 1+2+⋯+2n−1 children.
3. Subtract the one original process: 2n−1, B. Counting only n forks by the original parent misses descendants’ forks.

Original paper, page 13