CS 3733 Operating Systems, Spring 2002 Assignment 3


Due Thursday, March 21, 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

  1. The standard configuration.
  2. Change After fork from parent to child.
  3. Change After fork from parent to either.
  4. Change After fork from parent to random.
  5. Change Choose Process from FCFS to Random.
  6. Change Scheduling from no preempt to round robin with a quantum of 5 and Choose Process from FCFS to Random.
  7. Repeat the experiment above with a quantum of 2 and see if it behaves differently.
  8. Change Print Atomic to Print Not Atomic with probability 0.1.
  9. Insert a wait(NULL) call before the fprintf statement.
  10. 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:

  1. For which of the 10 experiments was the output in the same order each time it was run?
  2. For which of the 10 experiments is the order of the output determined by the program?
  3. 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:

  1. The default configuration
  2. after fork: child
  3. after fork: parent, Scheduling RR, quantum = 2
  4. 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:
  1. Is the tree structure the same in each case? How does it differ?
  2. The process IDs are assigned in the order of creation. In each case describe the order of creation relative to the tree structure.
  3. Is the order of the output affected by the scheduling of the processes?


Use the cover sheet to hand in your assignment. Your log file 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.


Extra Credit (2 points)
Use the simulator to show a mutual exclusion can be done using a single pipe. Start with the ChainOfProcesses program and insert code before the loop that creates a ring of one process. Set Print Not Atomic with probability 0.1 and run the program. Look at the output window. The output should be garbled.

Now, after the loop, have the first process write a byte to the pipe after it prints its message. All other processes read a byte from the pipe, print the message, and then write a byte to the pipe.

To read and write bytes to the pipe, go into Mode: Program and make a new char variable. Choose New Variable, then char, and then type the name of the variable in the New Char Variable box. Hit ENTER and the box will disappear.

Use the instruction write(1,&var,1) to write one byte to the pipe. You will be prompted for the variable to use. Choose the one you created above.

In a similar way you can use the read(0,&var,1) instruction to read a byte from the pipe.

Create a log file containing your final program and showing the output generated for two programs both with non-atomic print. The first run will be the standard ChainOfProcesses and the second will be your version that uses the pipe for mutual exclusion.