CS 3733 Operating Systems, Fall 2002 Assignment 3
Due Thursday, October 31, 2002
In this assignment you will use the ring simulator to explore
process scheduling and synchronization.
Read the exercises after Program 4.1 in the text to get a feel for the
problem. However, you will just be using the simulator and do not
have to compile any programs.
Make a directory called assign3 for all of the files for this
assignment.
Part 0
Copy all of the files from
/usr/local/courses/java/ringfiles
into your assign3 directory.
Modify the ringconfig file so the the user line contains
your name instead of Local User. Make sure that
/usr/local/courses/java/bin is in your path and run the ring
simulator using
runring
The simulator should come up and you should be able to create a log file.
Part 1
Open a log file and keep a log of the output generated for each set of runs
described below.
You can display the output generated by the simulated program by clicking on
the Display Info button and then Display Output.
Run the program several times (at least 3)
with the configuration indicated and put the resulting output in the log
file. Push the Reset button between runs. After logging the
output, push the clr button on the output window before starting
the next set of runs.
Try each of the following and record the output generated by the
simulated program.
After each of these, change back to the standard configuration:
After fork: parent
Choose Process: FCFS
Scheduling: no preempt
Print Atomic
- The standard configuration.
- Change After fork from parent to child.
- Change After fork from parent to either.
- Change After fork from parent to random.
- Change Choose Process from FCFS to Random.
- Change Scheduling from no preempt to round robin with a quantum of 5
and Choose Process from FCFS to Random.
- Repeat the experiment above with a quantum of 2
and see if it behaves differently.
- Change Print Atomic to Print Not Atomic with probability 0.1.
- Insert a wait(NULL) call before the fprintf statement.
- Change Print Atomic to Print Not Atomic with probability 0.1
and insert a wait(NULL) call before the fprintf statement.
You do not have to put all 10 runs in the same log file, but remember to change
the name of the log file so you do not overwrite previous ones. On some systems
the simulator may run out of memory after a few runs, so save your log file and
be prepared to restart the simulator if necessary.
After running each experiment (which consists of three or more runs with
the same parameters) log the output and then clear the output.
After running all of the experiments, answer the following questions:
- For which of the 10 experiments was the output in the same
order each time it was run?
- For which of the 10 experiments is the order of the output
determined by the ring program, rather than by the way the processes are
scheduled?
- For experiments 1, 8, 9 and 10 explain why you think the output
was in the order that it was?
Part 2
For this part you will run the Tree program. Use the Change Program
button in the second column can choose the TreeOfProcesses program.
This is
similar to the tree of processes of Example 2.7 of PUP. This will be run
with nprocs equal to 5, generating 16 processes.
Make 1 run of the simulator for each of the following:
- The default configuration
- after fork: child
- after fork: parent, Scheduling RR, quantum = 2
- after fork: parent, Scheduling RR, quantum = 3
After each run, move the processes around so that the tree structure is
apparent. The original process should be at the top. All of its children
should be at the next level.
The grandchildren of the original process should be on the next level, etc.
At each level, order the processes by the number of children they have with
the processes having the largest number of children on the left.
Log the diagram and the output for each experiment.
Make sure each log entry is labeled so you can tell which is which.
Answer the following questions:
- Is the tree structure the same in each case? How does it differ?
- The process IDs are assigned in the order of creation. In each case
describe the order of creation relative to the tree structure.
- Is the order of the output affected by the scheduling of the processes?
Part 3
For this part you will implement mutual exclusion using a token
passed around the ring. Start with the original ring program.
Set the simulator for "Print Not Atomic, Probability 0.1"
and Scheduling, RR, quantum 5.
Run the program and confirm the the output is interleaved.
Implement the token as follows. After the ring has been created,
but before anything is sent to standard error:
- Change the mode to Program Mode by using the Mode button at
the top of the third column.
- You can now move the pointer up or down using the buttons in the
third column.
- the first process (the one with i=1) writes its pid to standard output.
Do this with:
sprintf(buf,"%d",getpid())
write(1,buf,strlen(buf)+1);
- All processes then try to read from standard input using:
read(0,buf,BUFSIZE)
- Next comes the fprintf to standard error as before.
- All processes then write to standard output as in step 3.
- Click on the Mode button again to get back into Execute mode.
After you have this working, change the name of the program to
ringtoken. Use the button at the bottom left corner of the window.
Then save the program with the button above it. Modify your ringconfigfile to include this program name. You can then access it from the simulator
with the Change Program button (3rd in second column).
Run this and look at the output generated. You should see a message
about SIGPIPE. Figure out what this means and modify your program so
that it is not generated. Call the new program ringtoken1
and save is as before.
Part 4
For this part you will implement mutual exclusion using a semaphore.
Start with the original ring program.
Set the simulator for "Print Not Atomic, Probability 0.1"
and Scheduling, RR, quantum 5.
Run the program and confirm the the output is interleaved.
- Go into program mode.
- Create a semaphore using the New Variable button.
- Enter the name of the semaphore when prompted.
- The semaphore has been initialized to 1.
- Put wait and signal calls around the fprintf
- Go back into Execute mode.
Call this program ringsemaphore and save it. Modify your
ringconfig as before to include this program.
Use the cover sheet (available soon) to hand in your
assignment.
Your log files for parts 1 and 2 can be in several parts,
but number the pages consecutively
and fill in the index on the cover sheet. Then answer the questions
on the cover sheet.