in Operating System
2,150 views
3 votes
3 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
2.2k views

8 Answers

1 vote
1 vote
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