12_Operating Sytems-CPU Scheduling
12_Operating Sytems-CPU Scheduling
Computer Architecture
CT049-3-1-OS&CA
Ver: VE
CPU Scheduling
Learning Outcomes
• A CPU scheduler is tasked with choosing which process to run first from
the ready queue.
• A scheduling algorithm is used to choose the next process.
• Scheduling is a fundamental function of an operating system.
• Scheduling is done to ensure that the CPU is not idle.
• fairness
– to make sure all processes get a fair share of the
CPU time.
– avoid starvation.
• efficiency
– maximise CPU utilisation and keep the CPU busy
close to 100% of the time.
• response time
– consistent response time.
– minimise response time.
• turnaround time
– minimise time between submission and job completion.
– minimise output time.
• throughput
– maximise number of job completed within a given time period.
• CPU utilisation
• Throughput
• Turnaround time
– Average turnaround time
• Waiting time
– Average waiting time
• Response time
• Burst time
P1 P2 P3 P4 P5 P1 P5 P1 P5 P1 P1
0 2 3 5 6 8 10 12 14 15 17 19
Step 2:- Calculate waiting times and average waiting time
Time Slice = 2
TW(P1) = (0+6+2+1)=9 Milliseconds
TW(P2) = 2 Burst Time
Process (Milliseconds)
TW(P3) = 3
TW(P4) = 5 P1 10
TW(P5) = (6+2+2)=10 P2 1
TW(average)=(9+2+3+5+10)/5 P3 2
P4 1
=5.8 Milliseconds
Module Code & Module Title
P5
Slide Title
5 SLIDE 12
Round-robin
P1 P2 P3 P4 P5 P1 P5 P1 P5 P1 P1
0 2 3 5 6 8 10 12 14 15 17 19
highest
priority
System Processes
Interactive Processes
Batch Processes
Student Processes
lowest
priority
Module Code & Module Title Slide Title SLIDE 16
Multilevel Feedback Queue
quantum=8
quantum=16
FCFS
TT(P1) = (9+10) = 19
Burst Time
Process
TT(P2) = (0+1) = 1 (Milliseconds)
TT(P3) = (2+2) = 4
P1 10
TT(P4) = (1+1) = 2 P2 1
TT(P5) = (4+5) = 9 P3 2
(19+1+4+2+9)/5 = (35/5) P5 5
=7 Milliseconds
Module Code & Module Title Slide Title SLIDE 26
Priority
Step 1:- Draw Gantt Chart to represent timing for all processes
P4 P1 P3 P5 P2
0 1 11 13 18 19
TT(P1) = (1+10) = 11
TT(P2) = (18+1) = 19 Burst Time
Process Priority
TT(P3) = (11+2) = 13 (ms)
TT(P4) = (0+1) = 1 P1 10 3
P2 1 1
TT(P5) = (13+5) = 18 P3 2 3
Average turn around time is
P4 1 4
(11+19+13+1+18)/5 = (62/5) P5 5 2
=12.4 Milliseconds
Module Code & Module Title Slide Title SLIDE 29
Quick Review Questions
Q&A
Module Code & Module Title Slide Title SLIDE 34