1,383 views
1 votes
1 votes

The answer is given as 11. can anybody explain probably with a diagram?

2 Answers

1 votes
1 votes
if(!pid[k]) means we are entering the child process. On calling execvp() inside that process, that child process cannot call fork() on the next turn. Hence there are no exponential number of processes to consider. Therefore options c and d are elimintated.

The main process calls 10 forks each of which create one child each of which in turn call one execvp(). Hence the total number of processes created = 1 parent + 10 siblings = 11 processes created.
0 votes
0 votes

say for loop is executing k<=3, then picture will be this. isnot it?

Related questions

2 votes
2 votes
3 answers
3
Philosophical_Virus asked Dec 10, 2023
907 views
Int main (){fork();printf("a");fork();printf("b");return 0;}How many distinct outputs are possible of above code? And also give outputs
3 votes
3 votes
1 answer
4
24aaaa23 asked Oct 1, 2023
792 views
Consider the following code segment :int main (void) { for (int i=2; i<=5; i++) { fork( ); }printf (“GOCLASSES”);How many times “GOCLASSES” is printed by the ab...