The Wayback Machine - https://web.archive.org/web/20240118181847/https://www.geeksforgeeks.org/gate-gate-cs-2012-question-12/
Open In App
Related Articles

GATE | GATE CS 2012 | Question 8

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

A process executes the code

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

The total number of child processes created is
(A) 3
(B) 4
(C) 7
(D) 8


Answer: (C)

Explanation: Let us put some label names for the three lines

  fork ();    // Line 1
  fork ();   // Line 2
  fork ();   // Line 3

       L1       // There will be 1 child process created by line 1
    /     \
  L2      L2    // There will be 2 child processes created by line 2
 /  \    /  \
L3  L3  L3  L3  // There will be 4 child processes created by line 3

We can also use direct formula to get the number of child processes. With n fork statements, there are always 2^n – 1 child processes. Also see this post for more details.

Quiz of this Question

Level Up Your GATE Prep!
Embark on a transformative journey towards GATE success by choosing Data Science & AI as your second paper choice with our specialized course. If you find yourself lost in the vast landscape of the GATE syllabus, our program is the compass you need.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads