CS 3733 Operating Systems, Spring 1997 Assignment 3


Due on March 26 at noon

Note that this is due right after spring break. You should plan on completing this assignment before spring break. Do not count on the lab being availble during the break.

When turning in assignments use the cover sheet that will be provided and make sure that the cover sheet is completely filled in.


You are going to do an assignment similar to what is described inu PUP, section 4.1 starting on page 147. You may want to read that description to give you an idea of what is involved.

You can get a copy of the original ring.c that is in the text from /usr/local/courses/cs3733/pup/ch04.

Part 1

Obtain a copy of Program 4.1 and call it ring.c. Modify it so that it starts by printing a message to standard error in the form:
This program was modified by ...
and modify the message printed out by each process so that it prints its child process ID also:
This is process n with ID x, parent ID y, and child ID z
If the process has no child, it should print -1 for the child ID.

Run the program with 6 processes and describe the results. Explain why the program had the behavior you observed.

Part 2

Copy ring.c into ring2.c and modify ring2.c as follows. Use your audio library from Assignment 2 to have the program speak your name when it starts, in the same way it did in Part 3 of Assignment 2. The original parent should call open_audio_for_output() and do any audio initialization once before any forking is done. The children do not open the audio device or initialize for speaking numbers. Each process should call audio_close() before it exits. Have each process speak its process ID after the final fprintf statement. Run this with 6 processes and describe the results. Explain why the program had the behavior you observed. Consider both the screen output and the audio output.

Part 3

Copy audioobj.c into audioobj1.c and modify it as follows. Put a call to sleep(2) in the loop of audio_speak_num so that it delays for 2 seconds after speaking each digit. For the rest parts of this assignment you will be linking with this version of your audio library. You do not have to change your ring source code to do this, just your makefile. Create an executable called ring3 which is identical to ring2 except that it uses this modified audio library. Run this with 6 processes and describe the results. Explain why the program had the behavior you observed and compare it with Part 2.

Part 4

Copy ring2.c into ring4.c and modify ring4.c as follows. Insert a wait() before the final fprintf. Run the program with 6 processes and describe the result. Explain why the program had the behavior you observed.

Part 5

Copy ring2.c into ring5.c and modify ring5.c and modify it as follows. Note that you are using the program from Part 2 without the wait. Before the final fprintf send a token around the ring. When a process gets the token it outputs with fprintf and speaks its process ID, and then passes the token around the ring. Run the program with 6 processes and describe the result. Explain why the program had the behavior you observed.