$29.99
CECS 326-01 Assignment 1 (10 points)
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 chile processes terminated. Parent exits.
Submit on BeachBoard the source programs parent.cc and child.cc, a screenshot that shows successful
compile of both programs as well as a successful run, and a cover page that provides your name, your
student ID, course # and section, assignment #, due date, submission date, and a clear program description
detailing what the programs are about. Format of the cover page should follow the cover page template
posted on BeachBoard. The programs must be properly formatted and adequately commented to enhance
readability and understanding. Detailed documentation on all system calls are especially needed.