OPERATING SYSTEMS (CS 377)

Homework 2

Due: Monday 3rd Mar. 2003, 23:30

What to Hand In

Everyone must hand in their own work. Place in your Hand-In directory (~/cs377/hw2/) an ASCII file (i.e., raw text) called "hw2.txt" or a postscript file called "hw2.ps" that contains your name, user id, and answers to the questions listed below. If you use a non-ASCII editor (e.g., MSword), please make sure that you save your final file in ASCII format (we will not be able to grade your assignment if it is not in ASCII format). In MSword, there is a 'save text' option in the save dialog box. You can check the format on the linux side by using the shell commands 'cat', 'more', or 'less'. Answers need not be more than a few sentences (please keep you answers to the point).

The Questions

Processes and Threads:

1.
a) What are two differences between user-level threads  and  kernel-level threads?
b) Under what circumstances is one type better than the other?

2.
a) Describe the actions taken by a kernel  to context-switch between processes.
b) Describe the actions taken by a kernel  to context switch between kernel-level  threads.
c) Describe the actions taken by a thread library to context switch between user-level threads.

3.
a) What resources are  used when a thread is created?
b) How do they differ from those used when a process is created?

Scheduling:

4.
a) Define the difference between preemptive and non-preemptive scheduling.
b) Explain why strict non-preemptive scheduling is unlikely to be used in a computer center.

5. What is the effect on the Round Robin Algorithm of increasing the time slice to
arbitrarily large values?

6. Suppose that the following processes arrive for execution at the times indicated.
Each process will run the listed amount of time. In answering the questions, use
non-preemptive scheduling with zero context switch overhead and base all decisions
on the information that you have at the time the decision must be made.
 
 
Process
Arrival Time
Burst Time
P1
0.0
6
P2
0.3
3
P3
1.0
1

a) What is the average turnaround and waiting time for these processes with the
FCFS scheduling algorithm?

b) What is the average turnaround and waiting time for these processes with the
SJF scheduling algorithm?

c) The SJF algorithm is supposed to improve performance, but notice that we
chose to run process P1 at time 0 because we did not know that two shorter processes
would arrive soon. Compute what the average turnaround time will be if the CPU
is left idle  for the first 1 unit, and then SJF scheduling is used. Remember that
processes are waiting during this idle time, so their waiting time may increase.
This algorithm could be known as future-knowledge scheduling.

d) In the above problem assume a three level MLFQ; a process can execute in
the first level for 1 time unit, in the second level for 2 time units and in the third level
for 4 time units. Calculate the average turnaround and waiting times for each of the
processes.

Synchronization:

7. What advantage does the test&set instruction have over enabling  and disabling
interrupts? In which circumstance may we still prefer enabling and disabling
interrupts?

8. Semaphores. Suppose a building has a limit on the number of people that may be in the building at one time due to a fire code. Suppose this is a very popular place to visit, so the number of people inside must be monitored closely. Further, suppose that this building has N entrances and M exits. Construct an algorithm that could be used to control a set of turnstiles that would ensure that 1) only one person can enter or exit through a particular door at any one time, and 2) the room is allowed to be filled but is never allowed to exceed its legal capacity. Note that multiple people may pass through different doors simultaneously. Specifically, write pseudo code for the following two methods and for the initialization of the necessary state variables:

enter_building(int i)

where i is a value between 1 and N (you can assume that the value is legal). This method returns when the calling thread (the party goer) has successfully passed through entrance i and into the building, and otherwise blocks.

exit_building(int j)

where j is a value between 1 and M (you can assume that the value is legal). This method returns when the calling thread has successfully left through door j.

9. How much time did you spend on this assignment?


fagg@cs.umass.edu

Last modified: Sat Feb 15 01:42:59 EST 2003