0% found this document useful (0 votes)
4 views7 pages

Week 5b

Os Notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Week 5b

Os Notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CPU Scheduling

FCFS Convoy Effect


 A CPU bound job will hold CPU until done, or it
causes an I/O burst (rare occurrence, since
the thread is CPU-bound)
 long periods where no I/O requests issued, and CPU
held
 Result: poor I/O device utilization
 Example: one CPU bound job, many I/O bound
 CPU bound runs (I/O devices idle)
 CPU bound blocks
 I/O bound job(s) run, quickly block on I/O
 CPU bound runs again
 I/O completes
 CPU bound still runs while I/O devices idle (continues…)
Revision

•Turn Around time = Exit time – Arrival time


•Waiting time = Turn Around time – Burst time
Round Robin with Arrival Time
Process Id Arrival time Burst time
P1 0 5
P2 1 3
P3 2 1
P4 3 2
P5 4 3

•q=2
•Average Turn Around time = (13 + (12-1) + (5-2) +(9-3) + (14-4)) / 5 = 43 / 5 =
8.6 unit
•Average waiting time = ((13-5) + (11-3) + (3-1) + (6-2) + (10-3)) / 5 = 29 / 5 = 5.8
unit
Priority Scheduling
 A priority number (integer) is associated with each process
 The CPU is allocated to the process with the highest priority
(usually, smallest integer  highest priority)
 Two schemes:
• Preemptive
• Nonpreemptive
 Problem  Starvation – low priority processes may never
execute
 Solution  Aging – as time progresses increase the priority of the
process
 Note: SJF is priority scheduling where priority is the inverse of
predicted next CPU burst time
Summary

 FIFO:

 + simple
 - short jobs can get stuck behind long ones; poor I/O
 RR:

 + better for short jobs


 - poor when jobs are the same length
 SJF:

 + optimal (avg. response time, avg. time-to-completion)


 - hard to predict the future
 - unfair
Practice Problem
 Five processes P1 through P5 arrive at almost the same time. They have CPU
burst times of 10, 6, 2, 4, and 8 time units. Their priorities are 3, 5, 2, 1, and 4,
respectively. (Highest number means the highest priority).
 For each of the following scheduling algorithms, make Gantt charts and
determine the average waiting time and the average turnaround time. Ignore
context switching overhead.
 Round robin (for q=1 and q=3)
 First-come, first served (run in order P1, P2, P3, P4 and P5)
 Shortest job first (non-preemptive)

 Solve the above problem again if P1 arrives at time 0, P2 arrives at time 2, P3


arrives at time 3, P4 arrives at time 5 and P5 arrives at time 6. Use these
algorithms also in addition to the above:
 Shortest job first (preemptive)

You might also like