$30
CECS-326: Operating Systems
PROJECT 2
PARENT – CHILD PROCESSES
Name: ____________________________________
Last, First
ABSOLUTELY NO LATE PROJECTS WILL BE ACCEPTED
PROJECT DESCRIPTION:
Write a parent program and a child program using C/C++ to do the following. The parent program uses a
command line argument to generate 4 child processes. The parent program receives two integer numbers
A and B and a sleep time T from the command line arguments. The parent displays the two numbers,
sleeps for a random time modulo T, then passes these two numbers together with the child number and the
sleep time T to the 4 child process. The child program sleeps for a random time modulo T, then performs
an arithmetic operation on the two numbers as follows: Child 0 generates S = A+B (addition). Child 1
generates D = A-B (subtraction). Child 2 generates P = A*B (multiplication). Child 3 generates Q = A/B
(division). The child program displays the child number, its child PID, and the result of the computation.
The sleep time T must be a positive integer no larger than 50. Use a random seed number each time the
parent program is run.
Example of a program run is as follows:
linux90.cecs.csulb.edu:86p2 20 156 82
I am parent process, the maximum sleep time is 20 and the two numbers are 156 and 82
Forked child 4790
Forked child 4791
Forked child 4792
I am child number 0 with PID 4790, the sum is 238
Forked child 4793
I am child number 1 with PID 4791, the difference is 74
I am child number 3 with PID 4793, the quotient is 1 with remainder 74
I am child number 2 with PID 4792, the product is 12792
DOCUMENTATION:
The project must be carefully documented. The write-up must include: one page of problem analysis and
discussion (include a flow chart or structure chart when relevant), program listing with proper comments,
one page of output listing using typical values of A and B and sleeptime. The discussion should include
general considerations, UNIX function calls, any reasonable assumptions, and any other relevant
information. Attach this sheet as the front page of your project. Firmly staple the entire project together.
No folder is used.
END OF PROJECT 2