Lab Assignment--Semaphores


(Please do this lab in LINUX)

Write a program that forks a child process. Use a semaphore to control a shared resource file called "buffer". The child will gain the resource first. The child and parent will take turns reading from a file, incrementing a letter, and writing the letter to the file.

More Details:

Sample run:

%exercise2
A. The letter [A] modified by child
B. The letter [B] modified by parent
A. The letter [C] modified by child
B. The letter [D] modified by parent
A. The letter [E] modified by child
B. The letter [F] modified by parent
A. The letter [G] modified by child
B. The letter [H] modified by parent
A. The letter [I] modified by child
B. The letter [J] modified by parent
Semaphore removed
semop -- parent -- waiting for new letter to be READ: Identifier removed

Deliverables:

Submit 2 files to URCourses:

  1. The code
  2. Script containing:

Your marks will be based on:

  1. Submission of each file (/2)
  2. Script of the run (/1)
  3. Code completeness (/7)