2,041 views
1 1 vote

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

2 Answers

1 1 vote
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.
Position:
Show:

Related questions

5 5 votes
2 2 answers
470
470 views
GO Classes asked Jul 15
470 views
Consider the following C program. Assume that every $\texttt{fork()}$ call succeeds.int main(void) { unsigned long int i; for (i = 0; i < 6; i++) if (fork() >= 0) continu...
3 3 votes
1 1 answer
322
322 views
GO Classes asked Jul 15
322 views
Assume that every $\texttt{fork()}$ call succeeds.int main() { int a = 0; int rc = fork(); a++; if (rc == 0) { rc = fork(); a++; } else { a++; } printf("a is %d\n", a); }...
4 4 votes
1 1 answer
317
317 views
GO Classes asked Jul 15
317 views
Assume that every $\texttt{fork()}$ call succeeds.int main() { int pid; pid = fork() && fork(); if (!pid) printf("A\n"); else printf("B\n"); return 0; }How many times are...
5 5 votes
1 1 answer
296
296 views
GO Classes asked Jul 15
296 views
Consider the following program. Assume that every $\texttt{fork()}$ call succeeds.int main() { int p1 = 1, p2 = 2, p3 = 3; p1 = fork(); if (p2 0) p2 = fork(); if (p1 0)...