Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change the code below so that the if-else are inside a loop to loop 5 times and has a wait() and exit() -------------------------------------------------------------------------------------------------------------- #include #include

Change the code below so that the if-else are inside a loop to loop 5 times and has a wait() and exit()

--------------------------------------------------------------------------------------------------------------

#include #include #include #include

int main(void) { int x,i; int status; int pid,pid1,pid2,pid3,pid4,pid5; //process id for events x=19530; pid=fork(); if (pid==0) { printf("x = %d ",x); exit(EXIT_SUCCESS); } else { x=x-5; wait(&status); }

pid1=fork(); if (pid1 == 0) { printf ("ITERATION 1 "); printf ("Parent : x = %d ",x); x=x/5; printf ("Child : x = %d ",x); exit(EXIT_SUCCESS); } else { x=x/5; x=x-5; wait(&status); } pid2=fork(); if (pid2 == 0) { printf ("ITERATION 2 "); printf ("Parent : x = %d ",x); x=x/5; printf ("Child : x = %d ",x); exit(EXIT_SUCCESS); } else { x=x/5; x=x-5; wait(&status); } pid3=fork(); if (pid3 == 0) { printf ("ITERATION 3 "); printf ("Parent : x = %d ",x); x=x/5; printf ("Child : x = %d ",x); exit(EXIT_SUCCESS); } else { x=x/5; x=x-5; wait(&status); } pid4=fork(); if (pid4 == 0) { printf ("ITERATION 4 "); printf ("Parent : x = %d ",x); x=x/5; printf ("Child : x = %d ",x); exit(EXIT_SUCCESS); } else { x=x/5; x=x-5; wait(&status); } pid5=fork(); if (pid5 == 0) { printf ("ITERATION 5 "); printf ("Parent : x = %d ",x); x=x/5; printf ("Child : x = %d ",x); exit(EXIT_SUCCESS); } else { x=x/5; x=x-5; wait(&status); }

printf("Finished with all the processes. "); exit(EXIT_SUCCESS); 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

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago