The purpose of this assignment is to give you some hands-on experience in the use of UNIX semaphores.
Log into a UNIX system (site or osf1 for instance) and print and study the man pages for the semctl and semop system calls. Study the code of sem.c and shm.c on the course home page.
The Problem:
Implement the producer-consumer problem using semaphores in UNIX. The pseudo code can be found in Tanembaum's book and in the CNE Interprocess Communication tutorial module. Assume that the buffer has 8 slots that hold an integer number each.
The output of your program should show the number put in the buffer by the producer and the number retrieved by the consumer. Make your producer generate 100 items.
Turn in an individual report containing your program in the appendix. Run your program at different times of the day and verify if you see any difference in the results.
Write procedures called down and up to encapsulate the statements you need to do a down and up in UNIX. These procedures should take two parameters: semid and semnum (number of the semaphore in the array of semaphores indicated by semid).