A process executes the following code for (i = 0; i < n; i++) fork( ); The…

2017

A process executes the following code

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

The total number of child processes created are

  1. A.

    n2

  2. B.

    2n+1 -1

  3. C.

    2n

  4. D.

    2n -1

Attempted by 220 students.

Show answer & explanation

Correct answer: D

The loop executes n times, calling fork() in each iteration. Each call to fork() doubles the number of existing processes. After n iterations, there are 2^n total processes. Since one is the original parent process, the number of child processes created is 2^n - 1.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro