CS 110 Intro to Computer Systems
Semaphores Project
Version 1.00
Due 28 September, 9 PM
20 Points

Introduction

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. once awaken the Parent waits on an event (semaphore).
  5. Upon receiving the event, the Parent prints out the time and updates a semaphore indicating that it is exiting, and then dies.

Once started the Child:

  1. sleeps for 1 second
  2. prints out its PID
  3. prints out the Parent PID
  4. signals the event
  5. sleeps for 3 seconds
  6. once awaken, the Child prints out the time, waits for the parent to die, and then the child dies.

Stuff you NEED to Know/Do

Stuff you need to Turn-in and Submit

Implementation Notes:

Semaphore Notes:

Turing has only a certain number of semaphores. They get eaten up unless they are freed when your program terminates. You can use ipcs to see what semaphores are available, but it will only show ones which are yours, or are group or world readable. Thus using 0644 | IPC_CREAT for the third arg 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 which the CS Staff must remove, you will lose points.

Returning Semaphores to the System:

Last modified September 26, 01 by mike@cs.hmc.edu