Skip to content
Official PYQ · 2008

GATE CS 2008 Q66 — System Calls

Explain with AI

A process executes the following code

for(i=0; i<n; i++) fork();

The total number of child processes created is

Choose one option
View worked solution

Answer: B

To find the total number of child processes created, let us track the total number of active processes after each iteration of the loop.

Initially, before the loop begins, there is only 11 process (the original parent process).

  • Iteration 1 (i=0i = 0): The 11 existing process calls fork(), doubling the number of processes to 21=22^1 = 2.
  • Iteration 2 (i=1i = 1): Both of these 22 processes call fork(), doubling the total to 22=42^2 = 4.
  • Iteration kk: Each of the 2k−12^{k-1} processes calls fork(), resulting in 2k2^k processes.

After the loop finishes executing all nn iterations, the total number of processes running is:

Total Processes=2n\text{Total Processes} = 2^n

Since the execution started with 11 original parent process, the number of newly created child processes is:

Total Child Processes=Total Processes−1=2n−1\text{Total Child Processes} = \text{Total Processes} - 1 = 2^n - 1

Thus, the correct option is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore System Calls questions