Brock University -- Department of Computer Science
COSC 4P13 - Operating Systems Design and Implementation - Fall 2010
Due: 16th of November 2010, 3:30 pm in the class and to the directory
Late : 19th of November 2010, 1:00 pm to the secretary
Modify the original program of Assignment #2 (generating chain of processes) to protect its critical section. You may use for that the Linux specific semaphore operations or the SVR4 semaphore operations (adopted by Linux as one of its IPC and described in the man pages for ipc).
Extensive description of SVR4 (POSIX) semaphores operations is provided in the book "Practical Unix Programming" available on the library reserve.
Your program should proceed as follow:
- The parent process will create first a private semaphore for mutual exclusion, containing a single element, which can be read and written by its owner only. The parent will define moreover
two operations on this semaphore - semwait and semsignal and will initialize the semaphore element to 1.
- Each child will enter first its identification message (the same as in the original program) into a common buffer
using sprintf. After all the children have been spawned, each of them will try to print to the standard
error its message from this buffer, character by character using fputc.
The code segment used for printing will be the critical section of the child code which has
to be protected by the semaphore.
- After all the children have printed their messages, the parent process waiting for them
will remove the semaphore.
- All operations should be checked for successful execution.
Submit hardcopy of your program listing and examplary outputs for different number of processes to the instructor in the class.
Copy your executable files interactively from your assignment directory to the course
directory on Sandcastle using command submit4p13.
Computer Science home page
COSC 4P13 Home Page
URL of this document:
Instructor: J. A. Barchanski
(c) copyright Jerzy A. Barchanski