in Operating System
3,423 views
5 votes
5 votes

Consider the following piece of C code:
 

void main( ) {

      fork( );
      fork( ); 
      exit( ); 

} 

How many child processes are created upon execution of this program?

in Operating System
by
3.4k views

8 Answers

3 votes
3 votes
Total child process = 2^n -1  , where n is number of time fork will call

 

2^2-1 =3
0 votes
0 votes
here fork() fnction is executing twice and n=2.

we the nos of child processes are  (2^n)-1= (2^2)-1=4-1=3
0 votes
0 votes
Generally when a fork is called for n times then total number of child processes that is generated is 2^(n)-1

In the above problem it is called 2 times so it generates 2^(2)-1 =3 number of child processes will be generated.
0 votes
0 votes
No of child processes created is 2^n-1.

Here n is the number of times fork is called.

Related questions