Consider the execution of the following program (written in the C language).
// all headers needed are included
int main()
{
int i = 0;
while (i < 3){
if (fork() == 0){
i++;
}
i++;
printf("%d ", i); fflush(stdout);
waitpid(-1, NULL, 0);
}
return;
}
5(a) Draw the process graph for the main() function. [15 marks]
You should include main(), fork(), printf(), waitpid() in your process graph; you can skip fflush() in drawing the process graph; “i++” does not appear in the process graph.
Note that a process graph should not have any cycle. For example, let A and B are vertices in a process graph, “A →B →A” composes a cycle. If a function is invoked many times, each invocation should have a vertex in the process graph.
5(b) Calculate the number of feasible outputs of this program. [10 marks]
Show your steps on how you do the calculation step-by-step, with explanation of what program behaviors lead to the number of feasible outputs.