Dark Mode

1,359 views

1 vote

When the first fork() call is executed the parent copies itself. So now we have two process executing. These two when execute the 2nd fork call will result in 4 processes. At 3rd fork 2*4=8 and so on. Total 64 processes would be created. Out of 64 one is parent the other are children. Hence 63 is the answer.

0

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 2^{6} - 1 = No. of children of the process.

0 votes

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

In the 2^{nd} 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 3^{rd} 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.