A process executes the following code
for (i = 0; i < n; i++) fork();
The total number of child processes created is
(A) n
(B) 2n - 1
(C) 2n
(D) 2(n+1) - 1
Answer: (B)
Explanation:
F0 // There will be 1 child process created by first fork
/ \
F1 F1 // There will be 2 child processes created by second fork
/ \ / \
F2 F2 F2 F2 // There will be 4 child processes created by third fork
/ \ / \ / \ / \
............... // and so on
If we sum all levels of above tree for i = 0 to n-1, we get 2n - 1. So there will be 2n – 1 child processes. On the other hand, the total number of process created are (number of child processes)+1.
Note:The maximum number of process is 2n and may vary due to fork failures.Also see this post for more details.
Recommended Posts:
- GATE | GATE CS 2008 | Question 1
- GATE | GATE CS 2008 | Question 2
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 4
- GATE | GATE CS 2008 | Question 5
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 8
- GATE | GATE CS 2008 | Question 9
- GATE | GATE CS 2008 | Question 10
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 12
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 14
- GATE | GATE CS 2008 | Question 15
- GATE | GATE CS 2008 | Question 16
- GATE | GATE CS 2008 | Question 17
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 20
Improved By : kalpaj_12

