recategorized by
1,802 views
1 votes
1 votes

What is the number of child process created ?

Answer given was 63, BUT i am getting 9 !

recategorized by

2 Answers

0 votes
0 votes

Here's a rough explanation,

In the above figure, you can see that after every fork() there is a formation of 2 processes. And at the end we can also see that there are a total of 64 processes. But the process that started this whole chain is the first one(which is also the only supreme parent to all these children).

So we conclude that 26 - 1 = No. of children of the process.

0 votes
0 votes

During 1st iteration (i=0), there is 2 fork() calls so there will be 4 processes.

In the 2nd iteration (i=1), those 4 processes will execute 2 fork() calls i.e. 4 processes, so there will be 4*4 processes i.e. 16.

Similarly, in the 3rd iteration (i=2), those 16 processes will execute 2 fork() calls i.e. 4 processes, so there will be 16*4 = 64 processes.

Now the question is asking for number of child processes, so 64 – 1 = 63.

Hence the answer is 63 child processes.

Related questions

3 votes
3 votes
1 answer
1
0 votes
0 votes
2 answers
2
Overflow04 asked Aug 29, 2022
863 views
On Solving manually I too getting 14 as answer. but on running more than 14 * are printed.
0 votes
0 votes
1 answer
3
Erwin Smith asked Apr 11, 2023
781 views
void main() { int n = 1; if(fork()==0) { n = n<<1; printf(“%d, “, n); n = n <<1; } if(fork()==0) n=n+700; printf(“%d, “,n); }Which of the following output is not ...