You are on page 1of 16

TOPIC 2

MEMORY AND PROCESS


MANAGEMENT
Part 4
Priority Scheduling Algorithm

Priority scheduling picks the job that has the


highest priority.
In this algorithm, each process will have a
priority associated with it.
Lower number priority means higher priority.
Priority algorithm can be either preemptive OR
non-preemptive. We will only cover non-
preemptive priority algorithm.
In non-preemptive Priority, response time is the
same as turnaround time.
Cont..

Process Burst time Priority


P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
 Assume that all processes arrived at time 0.
 First of all, Process 2 will get the CPU as it has the
highest priority 1 and will finish.
 Then Process 5 will start execution.
 Then Process 1 will execute.
 Then Process 3 and the last one is Process 4.
Turnaround Response
Process Burst time Priority Finish Time Waiting Time
Time Time
P1 10 3 16 6 16 16
P2 1 1 1 0 1 1
P3 2 3 18 16 18 18
P4 1 4 19 18 19 19
P5 5 2 6 1 6 6

• Gantt Chart:

• Waiting time = Finish time – Burst time - Arrival time


• Turnaround time = Waiting time + Burst time
• The AWT is: (6 + 0 + 16 + 18 + 1) / 5 = 8.2
• The ATT is: (1+6+16+18+19)/5 = 12
• The ART is: (1+6+16+18+19)/5 = 12
Exercise

• Arrival time=0 for all.


Process Burst time Priority
P1 10 2
P2 20 4
P3 9 1
P4 4 3

• Gantt Chart: ?

• Average waiting time = ?


• Average turnaround time = ?
• Average response time = ?
Exercise

• Arrival time=0 for all.


Process Burst time Priority
P1 10 2
P2 20 4
P3 9 1
P4 4 3

• Gantt Chart: ?

• Average waiting time = 12.75


• Average turnaround time = 23.5
• Average response time = 23.5
Round Robin

RR assigns a small amount of time to each process in


which it executes.
This small time unit is called the time quantum or time
slice.
When the time quantum expires, the process is
preempted from the CPU and replaced by the next
process in a circular queue.
Round Robin is an example of preemptive scheduling.
Response time for RR = First response time – Arrival
time.
Cont..
 In this RR, time quantum/slice is 4
Turnaround Response
Process Arrival time Burst time Finish time Waiting time
time time

P1 0 20 26 6 26 4-0=4
P2 0 3 7 4 7 7-0=7
P3 0 3 10 7 10 10-0=10

 Gantt Chart:

P1 P2 P3 P1 P1 P1 P1
0 4 7 10 14 18 22 26

 Waiting time = Finish time - burst time - arrival time


 Turnaround time = Waiting time + Burst time
 Average waiting time = (6 + 4 + 7)/3 = 5.67
 Average turnaround time: (26+7+10)/3 = 14.33
 Average response time: (4+7+10)/3 = 7
Cont..

P1
5th Round
4 unit
time
P2
P1
P3
433unit
unittime
unit time
time P1
4th Round 4 unit
time

1st Round P1 P1
4 unit 4 unit
time time

2nd Round 3rd Round


Exercise

• Time quantum / slice is 4, arrival time=0 for all.


Turnaround Response
Process A.T Burst time Finish time Waiting time
time time
P1 0 10
P2 0 7
P3 0 6
P4 0 2

• Gantt Chart: ?

• Average waiting time = ?


• Average turnaround time = ?
• Average response time = ?
Exercise

• Time quantum / slice is 4, arrival time=0 for all.


Turnaround Response
Process A.T Burst time Finish time Waiting time
time time
P1 0 10
P2 0 7
P3 0 6
P4 0 2

• Gantt Chart: ?

• Average waiting time = 14.5


• Average turnaround time = 20.75
• Average response time = 9.5
Multilevel Queue (MLQ)

• MLQ partitions the ready queue into several queues, i.e. :


– foreground (interactive) processes
– background (batch) processes

• Each queue has its own scheduling algorithm, depends


on its requirements. Example:
– foreground – RR
– background – FCFS

• In addition, there must be a scheduling algorithm among


the queues. For example:
• 80% time to foreground in RR
• 20% time to background in FCFS
S
C
H
E
D
U
L
I
N
G
CPU
A
L
G
O
R
I
T
H
M

Several queues, each with own scheduling technique


Multilevel Feedback Queue

• MLFQ also partitions ready queue into several separate


queues, but it has additional features.

• MLFQ allows a process to move between queues.

• If a process waits too long in a lower-priority queue, it may


be moved to a higher-priority queue.

• If a process uses too much CPU time, it will be moved to


lower-priority queue.

• MLFQ is preemptive.
MLFQ allows a process to move between queues
Q&A

You might also like