05 CPUScheduling
05 CPUScheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
CPU Scheduling
4.2
1 2
4.3 4.4
3 4
4.5 4.6
5 6
1
Scheduling Criteria Optimization Criteria
CPU utilization – keep the CPU as busy as possible
Max CPU utilization
Throughput – # of processes that complete their execution per
Max throughput
time unit
Min turnaround time
Turnaround time – amount of time to execute a particular
process Min waiting time
Waiting time – amount of time a process has been waiting in the Min response time
ready queue
Response time – amount of time it takes from when a request
was submitted until the first response is produced, not output
(for time-sharing environment)
4.7 4.8
7 8
P1 P2 P3
Process Burst Time
P1 24 0 24 27 30
P2 3
P3 3
Waiting time for P1 = 0; P2 = 24; P3 = 27
Suppose that the processes arrive in the order: P1 , P2 , P3
Average waiting time: (0 + 24 + 27)/3 = 17
4.9 4.10
9 10
Suppose that the processes arrive in the order Associate with each process the length of its next CPU burst. Use these
P2 , P3 , P1 lengths to schedule the process with the shortest time
4.11 4.12
11 12
2
Example of Non-Preemptive SJF Example of Non-Preemptive SJF
Process Arrival Time Burst Time Process Arrival Time Burst Time
Queue Queue
P1 0.0 7 P1 0.0 7
P2 , 4 P2 , 4
P2 2.0 4 P2 2.0 4
P3 4.0 1 P3 , 1 P3 4.0 1 P3 , 1
P4 5.0 4 P4 , 4 P4 5.0 4 P4 , 4
SJF (non-preemptive)
P1 P3 P2 P4
0 3 7 8 12 16
Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Average turnaround time = ( 7 +10 +4 +11)/4 = 8
4.13 4.14
13 14
0 2 4 5 7 11 16
4.15 4.16
15 16
4.17 4.18
17 18
3
Example of RR with Time Quantum = 20
Multilevel Queue
Queue
4.19 4.20
19 20
4.21 4.22
21 22
Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is served FCFS. When it gains
CPU, job receives 8 milliseconds. If it does not finish in 8
milliseconds, job is moved to queue Q1.
At Q1 job is again served FCFS and receives 16 additional
milliseconds. If it still does not complete, it is preempted and moved
to queue Q2.
4.23 4.24
23 24
4
Thank you
25