Sie sind auf Seite 1von 7

CSC 501: Operating System Principles

Fall 1998
Problem Set 1 with Solutions

Problems 1, 2 and 3 were graded. There are 70 points on this problem set, for 4% of your grade
(8% if it is one of your two best homeworks).

Problem 1. (25 points) Consider the following process arrival list:

Name Arrival Time Service Time


A 0 4
B 2 5
C 4 8
D 7 1
E 10 3
F 12 2
G 23 6

Consider these scheduling disciplines:

(a) First-come first-served (FCFS) (d) Round-robin (RR), quantum = 1


(b) Shortest-job next (SJN) (e) Round-robin (RR), quantum = 5
(c) Shortest remaining time (SRT)

Draw a Gantt chart (time line) showing which process is executing over time and calculate the
turnaround time and waiting time for each process.

In SRT, if a job arrives whose service time is equal to the remaining service time of the job
currently being served, the current job is not interrupted.

In RR, if the queue is empty, and a process arrives at the same time a quantum finishes, the
running process is preempted and the new arrival executes. When a process gets interrupted by
a new arrival, it goes to the end of the ready queue. For example—

Solution 1. In the Gantt charts below, I have shown which processes are in the queue, and in
which order. If there are processes in the queue for a particular time period, they are shown
above the process that executes during that time period, in the order that they occupy in the
queue, with the next process to execute at the bottom. In the selfish round-robin diagram, only
the round-robin queue of accepted jobs is shown.

(a) FCFS.

Name Response time Waiting time


A 4 0
B 7 2

–1–
C 13 5
D 11 10
E 11 8
F 11 9
G 6 0
Avg. 9 4.86

(b) Shortest-job next.

Name Response time Waiting time


A 4 0
B 7 2
C 19 11
D 3 2
E 3 0
F 3 1
G 6 0
Avg. 6.43 2.29

(c) SRT.

Name Response time Waiting time


A 4 0
B 8 3
C 19 11
D 1 0
E 3 0
F 3 1
G 6 0
Avg. 6.29 2.14

In the Gantt charts below, I have shown which processes are in the round-robin queue, and in
which order. If there are processes in the queue for a particular time period, they are shown
above the process that executes during that time period, in the order that they occupy in the
queue, with the next process to execute at the bottom. In the selfish round-robin diagram, only
the round-robin queue of accepted jobs is shown.

(d) RR with quantum = 1.

Name Response time Waiting time


A 7 3

–2–
B 12 7
C 19 11
D 3 2
E 10 7
F 6 4
G 6 0
Avg. 9 4.86

(e) RR, with quantum = 5.

Name Response time Waiting time


A 4 0
B 7 2
C 19 11
D 8 7
E 8 5
F 8 6
G 6 0
Avg. 8.57 4.43

Problem 2 [15 points] (Silberschatz & Galvin, 5.4, slightly modified) Suppose the following jobs
arrive for processing at the times indicated. Each job will run the listed amount of time. What is
the average turnaround time for these jobs? Use non-preemptive scheduling and base all
decisions on the information you have at the time the decision must be made.

Job Arrival Time Execution Time


A 0.0 8
B 0.5 4
C 1.0 1

(a) FCFS

Solution:

Completion Arrival
time time

Average turnaround time = 8 – 0


12 – 0.5
13 – 1
31.5 Ö 3 = 10.5

(b) SJF

Solution:

Completion Arrival

–3–
time time

Average turnaround time = 8 – 0


13 – 0.5
9 – 1
28.5 Ö 3 = 9.5

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

Solution:

Completion Arrival
time time

Average turnaround time = 14 – 0


6 – 0.5
2 – 1
20.5 Ö 3 = 6.67

Problem 3. (30 points) Use the following process information for parts (a) – (c).

Process Arrival Execution Priority


number time time
0 0 ms. 5 ms. 2
1 3 ms. 7 ms. 3
2 4 ms. 3 ms. 1
3 4 ms. 8 ms. 5
4 5 ms. 6 ms. 4

(a) Would a preemptive algorithm produce a larger, smaller, or same average turnaround time
versus a non-preemptive algorithm over these processes?

Solution: Here is the schedule for a non-preemptive priority discipline.

Completion times are 5, 13, 19, 26, and 29. These times sum to 92.

Here is the schedule for a preemptive priority discipline.

Completion times are 12, 18, 24, 26, and 29. These times sum to 109. Thus, a non-preemptive
discipline finishes the average job sooner, and hence produces a lower average turnaround time.

–4–
(b) Using preemptive priority scheduling, what would the average response time be over these
processes?

Solution: Response times are 3, 1, 9, 14, and 25, for an average response time ofof 52Ö5 =
10.4 ms.

(c) Would any scheduling discipline (FCFS, LCFS, SJN, SRT, RR quantum = 8) produce a better
average waiting time over this set of processes? If so, what is the scheduling discipline, and what
would the average waiting time be?

Solution: Yes, SRT produce the lowest average waiting time.

Waiting times are 0, 1, 3, 11, and 17, for an average waiting time of 32 Ö 8 = 4.0 ms. As can be
seen from the above Gantt chart, in this case SRT = SJF, so SJF also produces an optimal
waiting time.

(d) Which scheduling algorithms (FCFS, LCFS, SJF, SRT, RR, preemptive priority, non-
preemptive priority) could produce process starvation (a process waits forever without getting a
chance to execute)?

Solution: SJF, SRT, preemptive priority, and non-preemptive priority can produce starvation if
new jobs keep arriving fast enough.

Problem 4. (15 points) For the following processes with given execution times—

(a) draw the Gantt charts for FCFS, RR with q=1, RR with q=3, and SJF.

(b) give the total execution times for a context switching time of s = 0.05 units and for s = 0.1
units. Assume there’s no context switch before the first process or after the last.

(c) give the average waiting time for a context switching time of s = 0, s = 0.05 units and for s =
0.1 units. Assume there’s no context switch before the first process or after the last.

Process Exec. time


A 4
B 3
C 5
D 1

Solution 4.

FCFS:

Total execution time s = 0.05: 13.15


Total execution time s = 0.1: 13.3

–5–
Average waiting time s = 0.0: (0 + 4 + 7 + 12) / 4 = 5.75
Average waiting time s = 0.05: (0 + 4.05 + 7.1 + 12.15) / 4 = 5.83
Average waiting time s = 0.1: (0 + 4.1 + 7.2 + 12.3) / 4 = 5.90

RR (q = 1):

Total execution time s = 0.05: 13.7


Total execution time s = 0.1: 14.2
Average waiting time s = 0.0: (7 + 6 + 8 + 3) / 4 = 6.00
Average waiting time s = 0.05: (7.5 + 6.4 + 8.6 + 3.15) / 4 = 6.41
Average waiting time s = 0.1: (8.0 + 6.8 + 9.2 + 3.3) / 4 = 6.82

RR (q = 3):

Total execution time s = 0.05: 13.25.


Total execution time s = 0.1: 13.5
Average waiting time s = 0.0: (7 + 3 + 8 + 9) / 4 = 7.75
Average waiting time s = 0.05: (7.2 + 3.05 + 8.25 + 9.15) / 4 = 6.9125
Average waiting time s = 0.1: (7.4 + 3.1 + 8.5 + 9.3) / 4 = 7.075

SJF:

Total execution time s = 0.05: 13.15


Total execution time s = 0.1: 13.3
Average waiting time s = 0.0: (4 + 1 + 8 + 0) / 4 = 3.25
Average waiting time s = 0.05: (4.1 + 1.05 + 8.15 +0) / 4 = 3.325
Average waiting time s = 0.1: (4.2 + 1.1 + 8.3 + 0) / 4 = 3.4

Problem 5. (15 points) Consider a variant of the RR scheduling algorithm where the entries in
the ready queue are pointers to the PCBs, and PCBs may contain priority values.

(a) What would be the effect of putting two pointers to the same process in the ready queue?

Solution: If two pointers to the same process are inserted in the ready queue, then the process
concerned will be given twice as much CPU time as the other processes. This means that in this
scheme, a process can be given a priority over other processes by inserting two pointers to its
process control block in the ready queue.

For example, let there be three processes p1, p2, and p3 in the ready queue. For RR with q = 1,
the schedule is

and so on. (p1, p2, and p3 are pointers to the PCB's of the respective processes).

–6–
If process p1 has two pointers in the ready queue, before the pointer to p2 and before the pointer
to p3, then the schedule looks like this:

(b) How would you modify the basic RR algorithm to achieve the same effect without the
duplicate pointers?

Solution: By allowing insertion of more than one pointer to the PCB in the ready queue we are
able to allocate more CPU time to processes within a single cycle. This can be achieved without
having to introduce duplicate pointers as mentioned above.

A process control block contains information regarding resources required by a process


for execution on the CPU. To allow more time to be given to a process on the CPU, additional
information regarding the priority of the process should be stored in the PCB. This can be in
the form of a priority number. The higher the priority number, the greater the frequency with
which the process will be scheduled in one cycle. So,based on the priority number in the PCB
the particular process segment is re-positioned in the ready queue repeatedly to satisfy its priority
requirements in the PCB.

–7–

Das könnte Ihnen auch gefallen