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
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
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