Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Now modify the code of prog5.c to make it do the following: a) Have the child process return a value of 75 (to simulate that

image text in transcribed
image text in transcribed
Now modify the code of prog5.c to make it do the following: a) Have the child process return a value of 75 (to simulate that it encountered a database connection issue). b) Have the parent process detect that it returned a non-zero value by printing it. The output of prog5.o should look something like: I am the parent process (PID: 3852). I created a child process with PID 3853 I am the child process (PID: 3853). Unable to open connection to database I am the parent process (PID: 3852). Status of child process is 75 nain of process with PID 3852 ends Note that you have to use wait: int status = 0; wait(&status); And to print the value of status you can use the WEXITSTATUS macro: WEXITSTATUS(status) Include prog4.c and a snapshot of the output with you submission. #include #include #include int main(int argc, char* argv[]) { int retval = fork(); int mypid; if(retval == 0){ //the child process mypid = getpid(); //Assume tyhe child process is doing some complicated //computation that takes 5 seconds sleep(5); printf("I am the child process(PID: %). Done with my workin", mypid); }else if(retval > 0) { //The parent process mypid = getpid(); printf("I am the parent process(PID: %d). I created a child process with PID %d ", mypid, retval); }else{ //call to fork failed fprintf(stderr, "Error while calling fork "); wait(NULL); printf("main of process with PID %d ends ", mypid); 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

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

5. What information would the team members need?

Answered: 1 week ago