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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started