Due: Tuesday 12/7 8:00 am

You’re going to write a telephone style game! It will use a semaphore to control access to a file and shared memory.

Before doing any of this check out the notes page for information on using semaphores in c. At the bottom are full code snippets that demonstrate the usage. You can also check the dwsource repository for some programs that use shared memory and semaphores.

Also note this is due Tuesday, as I will spend some class time on Monday clearing up any questions or issues you may have.

You will need 2 programs, one to create/monitor/remove the file, shared memory and semaphore, and one to use those structures to implement the telephone style game:

  • Control program:
    • Should take a command line argument to determine if it is creating or removing the resources.
    • If creating:
      • Should make the shared memory, semaphore and file (open the file with the truncate flag).
      • Set any values that are needed.
    • If removing
      • Remove the shared memory and the semaphore
      • Display the full contents of the story.
  • The writing program
    • Will attempt to access the resources using the semaphore
    • Once in, it should display the last line added to the file (the shared memory should contain the size of the last line).
    • Then prompt the use for the next line.
    • Once a new line is added, it should write that to the file, update the shared memory and then release the semaphore