Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question About Forking: Including the initial parent process, how many processes

ID: 3842820 • Letter: Q

Question

Question About Forking:

Including the initial parent process, how many processes are created by the program shown below? Show through a diagram the tree of process created giving process labels as P1, P2, P3, …

int main()

{

/* fork a child process */

fork();

/* Another fork */

fork();

int i;

for (i=0; i <5; i++)

fork();

/* fork another child process */

return 0; }

( I'd take a complete answer, but I'm mainly confused as to whether the initial 2 forks count in the "For" part of the process. Does int i start at i=0 or i=2? Would it go through a total of 4 forks or 6?)

Explanation / Answer

Yeah, initial 2 forks don't count in the for loop. They are separated from the forks created by the for loop. So, there are total 7 forks created. 2 by individual calls and 5 forks from for loop.

Hope it helps, feel free to comment in case of any query.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote