Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program which performs the following: 1) Creates a new child process using the fork() system call. If the fork() fails you should

Write a C++ program which performs the following:

1) Creates a new child process using the fork() system call. If the fork() fails you should display an error. If child process is successfully created, it should:

a. Identify itself by displaying its child process-id (e.g., I am a child process and my is ID = XXXX)

b. It then proceeds and calls the function named generateOddNumbers(int upperBound) which generates odd numbers from 1 to upperBound.

c. The child then indicates that it is finished and about to exit, then dedicates her work to her parents process by thanking the parent. (e.g. I wish to dedicate my work to my parent, ID = YYYY)

2) The parent process should

a. First Introduce itself and provide its ID = YYYY,

b. Then explain what the child is going to do

c. Then lovingly wait for the child to complete its work

d. Finally praise the child process by displaying the message good child!

e. Of course, by now the child is no longer living. Sad! So, it would be fitting for the parent to acknowledge the child by invoking the childs process id.

Sample output:

I am the parent process and my id is YYYY. My child will be displaying odd numbers.

I will now wait for my child to finish work. . parent waiting patiently ..

I am a child process and my is ID = XXXX

1

3

5

I am finished and about to exit

I wish to dedicate my work to my parent, ID = YYYY

Good child!

RIP XXXX

Hackers Corner

How about having the parent create another child process to display the even numbers! The parent can then wait for both child processes to finish before it displays its final remarks.

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

true or false The climate of my leadership is not important

Answered: 1 week ago