Please write in C++ and run in linux. This assignment is about fork(), exec(), and wait() system calls, and commandline arguments. Write two C++ programs, to be named parent.cc and child.cc and compiled into executable parent and child, respectively that, when run, will work as follows: parent takes in a list of gender-name pairs from the commandline arguments creates as many child processes as there are in the gender-name pairs and passes to each child process a child number and a gender-name pair waits for all child processes to terminate outputs “All child processes terminated. Parent exits.” And terminates.   child receives a child number and one gender-name pair arguments from parent outputs “Child # x, a boy (or girl), name xxxxxx.”                  Note: content of output depends on data received from parent   Sample run To invoke the execution: >parent girl Nancy boy Mark boy Joseph parent process does the following: outputs “I have 3 children.” -- Note: the number 3 comes from the number of gender-name pairs in the commandline arguments creates 3 child processes, and have each execute child and passes to it an integer that represents the child number and one gender-name pair arguments waits for all child processes to terminate, then outputs “All child processes terminated. Parent exits.” Output from child processes From first child process: Child # 1: I am a girl, and my name is Nancy. From second child process: Child # 2, I am a boy, and my name is Mark. From third child process: Child # 3, I am a boy, and my name is Joseph. Output from parent process All child processes terminated. Parent exits. please give: the source programs parent.cc and child.cc, a screenshot that shows successful compile of both programs as well as a successful run.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please write in C++ and run in linux.

This assignment is about fork(), exec(), and wait() system calls, and commandline arguments.

Write two C++ programs, to be named parent.cc and child.cc and compiled into executable parent and child, respectively that, when run, will work as follows:

parent

  1. takes in a list of gender-name pairs from the commandline arguments
  2. creates as many child processes as there are in the gender-name pairs and passes to each child process a child number and a gender-name pair
  3. waits for all child processes to terminate
  4. outputs “All child processes terminated. Parent exits.” And terminates.

 

child

  1. receives a child number and one gender-name pair arguments from parent
  2. outputs “Child # x, a boy (or girl), name xxxxxx.”                 
  3. Note: content of output depends on data received from parent

 

Sample run

To invoke the execution:

>parent girl Nancy boy Mark boy Joseph

parent process does the following:

  1. outputs “I have 3 children.” -- Note: the number 3 comes from the number of gender-name pairs in the commandline arguments
  2. creates 3 child processes, and have each execute child and passes to it an integer that represents the child number and one gender-name pair arguments
  3. waits for all child processes to terminate, then
  4. outputs “All child processes terminated. Parent exits.”

Output from child processes

From first child process:

Child # 1: I am a girl, and my name is Nancy.

From second child process:

Child # 2, I am a boy, and my name is Mark.

From third child process:

Child # 3, I am a boy, and my name is Joseph.

Output from parent process

All child processes terminated. Parent exits.

please give: the source programs parent.cc and child.cc, a screenshot that shows successful compile of both programs as well as a successful run.

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Random access
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education