Question: Now modify the program to create 2 children. The output should be the following: - I am the parent with pid: XXX - I am

Now modify the program to create 2 children. The output should be the following:

- I am the parent with pid: XXX

- I am the child with pid: XXX

- I am the child with pid: XXX

- I am the parent with pid: XXX and finishing after waiting for my kids.

The Code

#include #include #include #include

int main(int argc, char *argv[]) { printf("hello world (pid:%d) ", (int) getpid()); int rc = fork(); if (rc < 0) { // fork failed; exit fprintf(stderr, "fork failed "); exit(1); } else if (rc == 0) { // child (new process) printf("hello, I am child (pid:%d) ", (int) get$ sleep(1); } else { // parent goes down this path (original process) int wc = wait(NULL); printf("hello, I am parent of %d (wc:%d) (pid:%d$ rc, wc, (int) getpid());

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!