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.
Please write in C++ and run in linux.
This assignment is about fork(), exec(), and wait() system calls, and commandline arguments.
Write two C++
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.
Step by step
Solved in 4 steps with 3 images