in Operating System recategorized by
1,359 views
1 vote
1 vote

What is the number of child process created ?

Answer given was 63, BUT i am getting 9 !

in Operating System recategorized by
1.4k views

4 Comments

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

fork()

fork()

fork()

fork()

fork()

fork()

use formula = 2n-1 = 26-1 = 63

4
4
No of child process created = $2^{2*3} - 1$ = 63.
0
0
ok thanks
0
0

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