Question: 20. (12 points) Consider the C program given below (on the next page). Assume that all fork() and wait() calls complete successfully. Answer the following

20. (12 points) Consider the C program given below (on the next page). Assume that all fork() and wait() calls complete successfully.

Answer the following questions:

- (3 points) How many processes are created during the execution of this program (including the parent process)?

- (3 points) Draw the process hierarchy tree for this program.

- (3 points) In which order did the processes in the hierarchy tree start and complete? Why? Explain your answer.

- (3 points) Which processes (among those in the hierarchy tree) will execute the line marked by Do Computation. Explain your answer.

CODE FOR QUESTION 20:

#include #include #include #include

int main(void) { pid_t pid, pid2, pid3; int status, status2, status3; pid = fork(); if (pid == 0) { pid2 = fork(); if (pid2 == 0) { /* Do Computation */ return 0; } else { /* pid2 > 0 */ pid3 = fork(); if (pid3 == 0) { /* Do Computation */ return 0; } else { /* pid3 > 0 */ wait(&status3); printf( Process %d completed , pid3); } wait(&status2); printf(" Process %d completed ", pid2); } return 0; } else { /* pid > 0 */ wait(&status); printf(" Another process %d completed ", pid); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!