Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Intelligent Information And Database Systems Third International Conference Achids 2011 Daegu Korea April 2011 Proceedings Part 2 Lnai 6592

Authors: Ngoc Thanh Nguyen ,Chong-Gun Kim ,Adam Janiak

2011th Edition

3642200419, 978-3642200410

More Books

Students also viewed these Databases questions