Part 2: The following C program is executed on a LINUX OS. The system calls never fail, and function g never returns (we do not know how g is implemented under the hood; we just assume in this case that it is something like a black hole - the process that called it will not exit because the function does not return. Hence, the processes created in this program come to a permanent state.). The initial process executing the code arrives at line /* 22 */ in less than 5 seconds. The PIDs assigned by the system to the new processes are incremented by 1. Parent process PID == 1000.
Draw the associated process tree in its final form, i.e., when processes have reached a steady state. Explain how it arises. For every node, highlight the sys call/function that the related process executes, along with the arguments. Complete the process tree to illustrate Inter-process communication (IPC): for each data or signal transfer occurred, draw a dotted arrow from the sender to the recipient process. Above the arrow, type the value that is transferred each time (what you read below is only pseudo-code).
int i, j, n, fd[3][2];
pid_t p[3];
for (i = 0; i < 3; i++)
pipe(fd[i]);
for (i = 0; i < 3; i++) {
p[i] = fork();
if (p[i] == 0) {
for (j = i; j < 3; j++)
close(fd[j][1]);
sleep(5);
n = 3 - i;
if (i > 0)
write(fd[i - 1][1], &n, sizeof(n));
read(fd[i][0], &n, sizeof(n));
for (j = 0; j < n; j++)
if (fork == 0)
g(i, j);
wait(NULL);
g(i, 5);
n = 2;
write(fd[2][1], &n, sizeof(n));
kill(p[2], SIGKILL);
close(fd[1][1]);
/* Line 22 */
Wait(NULL);
g(i, n);
}
}