994 views

4 Answers

Best answer
19 votes
19 votes

Here we need to see no of times the innermost loop is running and hence no of times the fork() call is invoked..

So i ranges from 0 to 4 and j also ranges from 0 to 4..

So total times innermost loop runs  =   5 * 5  = 25

So fork() is called 25 times..

So we know :

If there is no condition of fork() invocation then no of parent process  =  1

No of child processes  =  2n  - 1 

Hence n = 25 here actually

Hence no of child processes created  =  225  -  1

                                                       =  33554431 

selected by
4 votes
4 votes

if there are n forks, number of child process created will be 2n-1 . Here ther are totally 25 forks. 

which means 225-1 = 33554431.

2 votes
2 votes

for (i=0;i<5,i++)      // this is executed 5 times     6 th time it fails the condition
  for (j=0;j<5,j++)   // this is executed 25 times   
      fork();                    // this is executed 25 times

standard formula

the above is similar to

for (i=0;i<25,i++)

fork();

225 -1

0 votes
0 votes
loop will execute 5*5 =25 time  so fork will also execute 25 time

so no. of child process=2^25-1