CS411/511. Operating Systems
Homework 2 - Solutions
Chapter 4: Review Questions 4.2, 4.6, 4.7
4.2. Describe the differences among short-term, medium-term, and long-term
- Short-term (CPU scheduler): selects a process from those that are
in memory and ready to execute, and and allocates the CPU to it.
- Medium-term (memory manager): selects processes from the ready or
blocked queue and removes them from memory, then reinstates them
later to continue running.
- Long-term (job scheduler): determines which jobs are brought into the
system for processing.
4.6. Describe the actions taken by a kernel to switch context
- (a) Among threads
- (b) Among processes
- The thread context (registers, PC, and stack, plus accounting info
if appropriate) must be saved and another thread's context must be
- The same as (a), except that the memory and resource info must also be
stored and that for the next process must be loaded.
4.7. What are the differences between user-level threads and kernel-supported
threads? Under what circumstances is one type "better" than the other?
- User-level threads have no kernel support, so they are very inexpensive
to create, destroy, and switch among. Kernel-supported threads are
more expensive because system calls are needed to create and
destroy them and the kernel must schedule them.
- In most current systems with threads, when a user-level thread blocks,
the whole process blocks. Since kernel-supported threads are
scheduled independently, they can block individually; that is,
the fact that one blocks does not hold up the others.
5.4. 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 nonpreemptive scheduling and base all
decisions on the information you have at the time the decision must
Process Arrival Time Burst Time
P1 0.0 8
P2 0.4 4
P3 1.0 1
- (a) What is the average turnaround time for these processes with the FCFS
- (b) What is the average turnaround time for these processes with the SJF
- (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 P1 and
P2 are waiting during this idle time, so their waiting time may
increase. This algorithm could be known as future-knowledge
Remember that turnaround time is completion time minus arrival time,
so you have to subtract the arrival times to compute the turnaround. FCFS
is 11 if you forget to subtract arrival time.
- (a) 10.53
- (b) 9.53
- (c) 6.86
5.6. What advantage is there in having different time-quantum sizes on
different levels of a multilevel queueing system?
- Processes which need more frequent servicing, such as interactive
processes, can be in a queue with a small q. Processes
that are computationally intensive can be in a queue with a larger
quantum, requiring fewer context switches to complete the processing,
making more efficient use of the CPU.
5.7. Consider the following preemptive priority-scheduling algorithm based on
dynamically changing priorities. Larger priority numbers imply higher
priority. When a process is waiting for the CPU (in the ready queue, but not
running), its priority changes at a rate alpha; when it is running,
the priority changes at a rate beta. All processes are given a
priority of 0 when they enter the ready queue for the first time. The
parameters alpha and beta can be set to give many different
- (a) What is the algorithm that results from beta > alpha
- (b) What is the algorithm that results from alpha < beta
- (a) Since processes start at 0, any processes that have been in the
system (either running or waiting) have higher priority. Therefore,
new processes go to the back of the queue. When a process runs,
its priority keeps increasing at the rate of beta, which
is more of an increase than for the processes in the ready queue.
Therefore, every time the process has timerrunout, it goes to
the front of the ready queue and gets dispatched again. This is
the equivalent of FCFS.
- (b) This time, any new processes entering the system have higher
priority than any old ones, since priority starts at zero and then
becomes negative when the process waits or runs. New processes go
in at the front of the queue. When a process runs or waits,
its priority decreases, with the waiting processes decreasing faster
than the running process. This is a LIFO (last-in-first-out)
algorithm. The question didn't promise that this would be
an algorithm you would want to use in real life.
Take the example that you just used for Question 5.4, and apply it to the
- (a) Calculate the average turnaround time for a Round-Robin algorithm
with q set at 2. Ignore the effects of context-switching
- (b) Calculate the average turnaround time for the same algorithm and
q, taking into effect the fact that each context switch costs
.5 units of time.
- (c) Suppose that a fourth process, P4, enters the system at time 7.6
and needs 6 units of CPU time. Also suppose that P2 and P3 are
interactive, but P1 and P4 are batch.
A multilevel queue (but not a multilevel feedback queue) is in
effect. The first queue is for interactive processes only, and
has a q of 1. The second queue is for batch processes,
which get up to 4 units each time they are in the CPU. Processes
are dispatched as follows: 2 processes are dispatched from the
interactive queue, followed by 1 process from the batch queue,
Calculate the average turnaround time.
- (b)10.53 (I didn't count the final context switch after a process
leaves the CPU for the last time)
- (c)11 (They run in the order P1-P2-P3-P1-P2-P4-P2-P4-P2)