Professional Documents
Culture Documents
P P P
1 2 3
2 2 3
0
4 7 0
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17
CONT
…
First Come First Served
▪ Suppose that the processes arrive in the order :
P2 , P3 , P1 (P1:24, P2:3, P3:3)
▪ The Gantt chart for the schedule is:
P2 P3 P1
0 3 6 30
▪ Waiting time for P1 = 6; P2 = 0; P3 = 3
▪ Average waiting time: (6 + 0 + 3)/3 = 3
CONT
Shortest Job First …
▪ This algorithm that assumes the run times are known in
advance.
▪ Associate with each process the length of its CPU burst.
▪ Use these lengths to schedule the process with the shortest time.
▪ Two schemes:
o Non-Preemptive: once CPU given to the process it cannot
be preempted until completes its CPU burst.
o Preemptive: if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt the current process. This scheme is know as the
Shortest-Remaining-Time-First (SRTF).
▪ SJF is optimal: gives minimum average waiting time for a
given set of processes.
Example #1: Non-Preemptive SJF
(simultaneous arrival)
Normal SJF
Process Burst Time
P1 7
P2 3
P3 4
P2 P3 P1
0 3 7 14
■ Average waiting time = (0 + 3 + 7)/3 = 3.33
Example #2: Non-Preemptive SJF
(simultaneous arrival)
Process Arrival Time Burst Time
P1 0.0 6
P2 0.0 4
P3 0.0 1
P4 0.0 5
⚫ SJF (non-preemptive, simultaneous arrival)
P3 P2 P4 P1
0 1 5 10 16
P1 P3 P2 P4
0 3 7 8 12 16
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
⚫ Average waiting time
= ( [(0 – 0) + (11 - 2)] + [(2 – 2) + (5 – 4)] + (4 - 4) + (7 – 5) )/4
= 9 + 1 + 0 + 2)/4
=3
⚫ Average turn-around time = [(16 -0)+ (7-2) +( 5 -4)+ (11-5))/4 = 7
CONT
Priority Scheduling …
▪ Gantt Chart
P2 P5 P1 P3 P4
0 1 6 16 18 19
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
⚫ Average waiting time = {[0+(10-4)]+4+7}/3 = 5.6
Example of RR with Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
⚫ The Gantt chart is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
⚫ Background P4 30 (FCFS)
P5 20
Multilevel Feedback Queue Scheduling
⚫ The multilevel feedback queue scheduling algorithm, allows a
process to move between queues.
⚫ The idea is to separate processes according to the
characteristics of their CPU bursts.
⚫ If a process uses too much CPU time, it will be moved to a
lower-priority queue.
⚫ This scheme leaves I/O-bound and interactive processes in the
higher-priority queues.
⚫ In addition, a process that waits too long in a lower-priority
queue may be moved to a higher-priority queue.
⚫ This form of aging prevents starvation.
Multilevel Feedback Queue Scheduling
Eg: