OS6 - Solutions Manual !!!!!!!!!!!!!
120 pág.

OS6 - Solutions Manual !!!!!!!!!!!!!

DisciplinaSistemas Operacionais I9.587 materiais186.279 seguidores
Pré-visualização31 páginas
A simple project is to write several different CPU schedulers and compare their performance
by simulation. The source of CPU and I/O bursts may be generated by random number genera-
tors or by a trace tape. The instructor can make the trace tape up in advance to provide the same
data for all students. The file that I used was a set of jobs, each job being a variable number of
alternating CPU and I/O bursts. The first line of a job was the word JOB and the job number.
An alternating sequence of CPU n and I/O n lines followed, each specifying a burst time. The
job was terminated by an END line with the job number again. Compare the time to process a
set of jobs using FCFS, Shortest-Burst-Time, and Round-Robin scheduling. Round-Robin is more
difficult, since it requires putting unfinished requests back in the ready queue.
Answers to Exercises
6.1 A CPU scheduling algorithm determines an order for the execution of its scheduled pro-
cesses. Given n processes to be scheduled on one processor, how many possible different
schedules are there? Give a formula in terms of n.
Answer: n! (n factorial = n \ufffd n \u2013 1 \ufffd n \u2013 2 \ufffd ... \ufffd 2 \ufffd 1)
6.2 Define the difference between preemptive and nonpreemptive scheduling. State why strict
nonpreemptive scheduling is unlikely to be used in a computer center.
Answer: Preemptive scheduling allows a process to be interrupted in the midst of its exe-
cution, taking the CPU away and allocating it to another process. Nonpreemptive schedul-
20 Chapter 6 CPU Scheduling
ing ensures that a process relinquishes control of the CPU only when it finishes with its
current CPU burst.
6.3 Consider the following set of processes, with the length of the CPU-burst time given in
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.
a. Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a
nonpreemptive priority (a smaller priority number implies a higher priority), and RR
(quantum = 1) scheduling.
b. What is the turnaround time of each process for each of the scheduling algorithms in
part a?
c. What is the waiting time of each process for each of the scheduling algorithms in part
d. Which of the schedules in part a results in the minimal average waiting time (over all
a. The four Gantt charts are
2 3 4 5 1 5 1 5 1 51 13 1 5
1 2 4 53
2 4 3 5 1
1 3 452
b. Turnaround time
FCFS RR SJF Priority
P1 10 19 19 16
P2 11 2 1 1
P3 13 7 4 18
P4 14 4 2 19
P5 19 14 9 6
c. Waiting time (turnaround time minus burst time)
Answers to Exercises 21
FCFS RR SJF Priority
P1 0 9 9 6
P2 10 1 0 0
P3 11 5 2 16
P4 13 3 1 18
P5 14 9 4 1
d. Shortest Job First
6.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 be made.
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 scheduling
b. What is the average turnaround time for these processes with the SJF scheduling al-
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 scheduling.
a. 10.53
b. 9.53
c. 6.86
Remember that turnaround time is finishing time minus arrival time, so you have to sub-
tract the arrival times to compute the turnaround times. FCFS is 11 if you forget to subtract
arrival time.
6.5 Consider a variant of the RR scheduling algorithm where the entries in the ready queue are
pointers to the PCBs.
a. What would be the effect of putting two pointers to the same process in the ready
b. What would be the major advantages and disadvantages of this scheme?
c. How would you modify the basic RR algorithm to achieve the same effect without
the duplicate pointers?
22 Chapter 6 CPU Scheduling
a. In effect, that process will have increased its priority since by getting time more often
it is receiving preferential treatment.
b. The advantage is that more important jobs could be given more time, in other words,
higher priority in treatment. The consequence, of course, is that shorter jobs will
c. Allot a longer amount of time to processes deserving higher priority. In other words,
have two or more quantums possible in the Round-Robin scheme.
6.6 What advantage is there in having different time-quantum sizes on different levels of a
multilevel queueing system?
Answer: Processes that need more frequent servicing, for instance, interactive processes
such as editors, can be in a queue with a small time quantum. Processes with no need
for frequent servicing can be in a queue with a larger quantum, requiring fewer context
switches to complete the processing, making more efficient use of the computer.
6.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 \ufffd;
when it is running, its priority changes at a rate \ufffd. All processes are given a priority of 0
when they enter the ready queue. The parameters\ufffd and \ufffd can be set to give many different
scheduling algorithms.
a. What is the algorithm that results from \ufffd > \ufffd > 0?
b. What is the algorithm that results from \ufffd < \ufffd < 0?
6.8 Many CPU scheduling algorithms are parameterized. For example, the RR algorithm re-
quires a parameter to indicate the time slice. Multilevel feedback queues require parame-
ters to define the number of queues, the scheduling algorithms for each queue, the criteria
used to move processes between queues, and so on.
These algorithms are thus really sets of algorithms (for example, the set of RR algorithms
for all time slices, and so on). One set of algorithms may include another (for example, the
FCFS algorithm is the RR algorithm with an infinite time quantum). What (if any) relation
holds between the following pairs of sets of algorithms?
a. Priority and SJF
b. Multilevel feedback queues and FCFS
c. Priority and FCFS
d. RR and SJF
a. The shortest job has the highest priority.
b. The lowest level of MLFQ is FCFS.
c. FCFS gives the highest priority to the job having been in existence the longest.
Answers to Exercises 23
d. None
6.9 Suppose that a scheduling algorithm (at the level of short-term CPU scheduling) favors
those processes that have used the least processor time in the recent past. Why will this al-
gorithm favor I/O-bound programs and yet not permanently starve CPU-bound programs?
Answer: It will favor the I/O-bound programs because of the relatively short CPU burst
request by them; however, the CPU-bound programs will not starve because the I/O-bound
programs will relinquish the CPU relatively often to do their I/O.
6.10 Explain the differences in the degree to which the following scheduling algorithms dis-
criminate in favor of short processes:
b. RR
c. Multilevel feedback queues
a. FCFS\u2014discriminates against short jobs since any short jobs arriving after long jobs
will have a longer waiting time.
b. RR\u2014treats all jobs equally (giving them equal bursts of CPU time) so short jobs will
be able to leave the system faster since they will finish first.
c. Multilevel feedback queues\u2014work similar to the RR algorithm\u2014they discriminate