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

Due Date

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

20 Points

Project Description

You are to expand on your fork program to have the parent controlled by the child.

After forking the child, the parent:

  1. Prints out its PID,
  2. Prints out the child's PID,
  3. Sleeps for 2 seconds,
  4. After the sleep is done, waits on an event (semaphore)
  5. Upon receiving the event, prints out the time,
  6. Updates a semaphore indicating that it is exiting, and
  7. Dies.

Once started, the child:

  1. Sleeps for 1 second,
  2. Prints out its PID,
  3. Prints out the parent's PID,
  4. Signals the event,
  5. Sleeps for 3 seconds,
  6. After the sleep is done, prints out the time,
  7. Waits for the parent to die, and
  8. Dies.

Stuff you NEED to Know and Do

Stuff You Need to Turn In or Submit

Implementation Notes

Semaphore Notes

Turing has only a certain number of semaphores. They get eaten up unless they are properly freed when your program terminates. You can use ipcs to see what semaphores are available, but it will only show ones that are yours, or are group or world readable. Thus, using 0644 | IPC_CREAT for the third argument of semget helps in determining who has all the semaphores.

Using 0 for the key means that the semaphore will be private to a single process and will not be seen by other processes, so don't do that.

If you end up with hidden semaphores that the CS Staff must remove, you will lose points.

Returning Semaphores to the System:

Last modified February 16, 2002, by geoff@cs.hmc.edu