In this assignment you will use the ring of processes, Program 4.1, to explore process scheduling and synchronization. Read the exercises after Program 4.1 in the text to get a feel for the problem.
Make a directory called assign3 for all of the files for this assignment.
Part 1
Make a directory called part1 under assign3 and
copy Program 4.1 from
/usr/local/courses/cs3733/pup/ch04/ring.c
into this directory.
Modify it so that the first thing it does after checking the command line
arguments is to print a line in the form:
This program was written by ...
in which it prints your name.
Compile it and make sure it works correctly.
Make any changes necessary to eliminate any lint warnings
which should not be there. Remember to use the -Xarch=v9 switch for lint.
Experiment with the program using 5 processes and determine
whether the order of the output is predictable. Look carefully at the output
generated including the IDs of the process and its parent. Note anything
unusual about the output. Use cut and paste
(not redirection) to save the output generated. Be prepared to explain
why the output might look as it does.
Now copy ring.c into ring1.c. Insert the statement
sleep(1);
into the parent code right after the fork.
Run this again with 5 processes and and determine whether the output is
predictable.
Use cut and paste (not redirection) to save the output generated.
Be prepared to explain why the output might look as it does.
Now copy ring.c into ring2.c. Insert the statement
sleep(1);
into the child code right after the fork.
Run this again with 5 processes and and determine whether the output is
predictable.
Use cut and paste (not redirection) to save the output generated.
Be prepared to explain why the output might look as it does.
Now copy ring.c into ring3.c. Insert a wait system call just before the final fprintf statement. Run this again with 5 processes and and determine whether the output is predictable. Use cut and paste (not redirection) to save the output generated. Be prepared to explain why the output might look as it does.
Part 2
Make a directory called part2 under assign3 and
copy all of the files from
/usr/local/courses/java/ringfiles
into this directory.
Modify the ringconfig file so the the user line contains
your name instead of New User. Make sure that
/usr/local/courses/java/bin is in your path and run the ring demo using
runring
You can display the output generated by the simulated program by clicking on the Show Output button. Run the program several times with the default ring program and determine if the output is consistent. Push the Reset button between runs.
Now try each of the following and record the output generated by the simulated program. You can store the output by opening the log file and pushing the Log button on the Output frame. You can use the Clr button to clear the contents of the the Output frame after logging a run.
After each of these, change back to the standard configuration:
After fork: parent
Choose Process: Next
Scheduling: no preempt
Print Atomic
Part 3 Extra Credit
Use the ring simulator to try to make a bidirectional ring.
If you are successful, use the Log button above the program
to put a copy of the program in the log file. Also, use the
Log Image button to put a picture of the ring created into the
log file. Be sure to move around the processes and pipes if necessary to
make it clear that it is a bidirectional ring. Also, print out the ring
for 10 processes after changing the Size to small.
Use the cover sheet when handing in this assignment. The cover sheet gives information about what needs to be handed in. Be sure to fill in the index on the cover sheet with page numbers so I can find the various parts of your assignment. Answer the questions on the back of the cover sheet.