A process execute the following code: For (I = 1; I ≤ n; I ++) fork (); How…

2025

A process execute the following code:

For (I = 1; I ≤ n; I ++) fork ();

How many child processes are created?

  1. A.

    n - 1

  2. B.

    2n - 1

  3. C.

    2n-1

  4. D.

    2n-1 -1

Attempted by 136 students.

Show answer & explanation

Correct answer: B

Option 2 : 2n - 1

Concept:

Fork () is a system call that creates a new process. After new child process is created, both processes will execute the next instruction. If fork() returns a negative value, creation of child process was unsuccessful. Return zero to newly created process.

Explanation:

If there are n fork() calls, then number of child processes created are 2n – 1.

Example:

For (I = 1; I ≤ 3; I ++) fork ();

Here n = 3,

Number of child processes created = 23 – 1 = 7

Explore the full course: Wipro Preparation