3,410 views

8 Answers

0 votes
0 votes

Given statements ,

  1. void main( ) {
  2.       fork( );
  3.       fork( );
  4.       exit( );
  5. }

At line #2,

           one child process will be created.

Now we have total 2 processes, 1 child process and another parent,

And the next statement to execute is line#3 in both processes.

 

At line #3


Now both processes(1 parent and 1 child process)  executes line#3 ,  and this will create two child processes.

One created by parent , And another by child (which was earlier created at line #2).


So,

total child processes are 1(line#2) + 2(line#3) → 3 child processes

 

 

General formula for calculating no. of child processes  (2^n) -1  (unless the fork is not called upon any condition)

0 votes
0 votes
yes  i am agree  with that fork is always creted process 2^n-1.(where n is the number of fork ()) and  finaly put the value of n and calculated the number of  child process … so calculated  answer is 3..

Related questions

0 votes
0 votes
1 answer
2
admin asked Oct 25, 2019
2,850 views
Five jobs are waiting to be run. Their expected run times are $9, 6, 3, 5,$ and $X$. In what order should they be run to minimize average response time? $($Your answer wi...
0 votes
0 votes
1 answer
4