retagged by
3,158 views

1 Answer

Best answer
28 votes
28 votes

Before going to this question, let analyze

for(i=1;i<=3;i++)

{

       fork();

}

it is equivalent to 

1.fork();

2.fork();

3.fork();

using fork() system call we create one more process ===> double the no.of processes

before the 1st line ===> totally you have 1 process

after the first line  ===> totally you have 2 processes

after the second line  ===> totally you have 4 processes

after the third line  ===> totally you have 8 processes ===> total = 2n processes

in this 8 process, 1 parent process, 3 intermediate processes , and 4 leave processes

Child processes = 3+4 = 7 ( note that every intermediate process is a child process for some process ) = 2n-1 processes

 

coming to your original question,

for(i=1;i<=3;i++)

{

       fork();
       fork();

}

it is equivalent to 

1.fork();

  fork();

2.fork();

  fork();

3.fork();

  fork();

 

it is equivalent to, let m=2n

for(i=1;i<=m;i++)

{

      fork();

}

===> child processes = 2m-1 =  22n-1 =  26-1 = 63

selected by

Related questions

2 votes
2 votes
3 answers
2
Philosophical_Virus asked Dec 10, 2023
878 views
Int main (){fork();printf("a");fork();printf("b");return 0;}How many distinct outputs are possible of above code? And also give outputs
0 votes
0 votes
1 answer
3
Erwin Smith asked Apr 11, 2023
781 views
void main() { int n = 1; if(fork()==0) { n = n<<1; printf(“%d, “, n); n = n <<1; } if(fork()==0) n=n+700; printf(“%d, “,n); }Which of the following output is not ...