CS 110, Architecture and Operating Systems
Fork Project, Version 1.00

Due Date

This project is due Friday, February 15, 2002, at 9 P.M.

10 Points

Project Description

Write a small program in C or C++ that has a parent and child process. The parent process forks the child, then calls a function that prints out the parent and child process id (with a tag indicating which pid is which). The parent then waits for the child to complete.

Once forked, the child calls a function that sleeps for a period of seconds. The sleep time in seconds is passed on the command line as the first argument to the program. Thus, there is data sharing between parent and child. After the child wakes up, it prints out the date and time (do not use system("date") to do the date; find the underlying OS system and library call) and terminates. The printout should differentiate between parent and child.

If you have problems with I/O, then make sure to flush.

What to Turn In and Submit

To Turn In:

Turn in (bin outside Geoff's office) a copy of your commented program and a script file of its execution (do a man script if you do not know what a script file is). On the script file, differentiate between parent and child output.

Script files end up with a lot of control characters. There are at least 2 ways to remove them. One is to try the command col; the other is to cat the file to the screen and then cut and paste.

To Submit:

Submit your source code and the script output by running cs110submit or cs110submitall. The script output must be named script.txt or the submit system will not accept it. Your source code must compile using make (in other words, you need to submit a Makefile with it).

This is assignment number 01.

Last modified March 4, 2002 by geoff@cs.hmc.edu