Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

What are five factors that cause the AD curve to shift?

Answered: 1 week ago

Question

Have ground rules been established for the team?

Answered: 1 week ago

Question

Is how things are said consistent with what is said?

Answered: 1 week ago

Question

Do you currently have a team agreement?

Answered: 1 week ago