Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition
Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates
CPU.
In non-preemptive scheduling , a running task is executed till completion.
The preemptive scheduling is prioritized. The highest priority process should always be the process that is currently utilized.
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition 5.2
Dispatcher gives control of the CPU to the process selected by the short-term scheduler; this involves:
Dispatch latency – time it takes for the dispatcher to stop one process and start another running
Operating System Concepts – 8 th Edition 5.3
Silberschatz, Galvin and Gagne ©2009
CPU utilization – keep the CPU as busy as possible
Throughput – # of processes that complete their execution per time unit.
Waiting time – amount of time a process has been waiting in the ready queue
Response time – amount of time it takes from when a request was submitted until the first response is produced.
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition 5.4
Scheduling Algorithm Optimization Criteria
Max CPU utilization
Max throughput
Min waiting time
Min response time
Operating System Concepts – 8 th Edition 5.5
Silberschatz, Galvin and Gagne ©2009
Burst Time:
Burst Time is actually time that is required to complete execution of particular task or process.
Operating System Concepts – 8 th Edition 5.6
Silberschatz, Galvin and Gagne ©2009
First-Come, First-Served (FCFS) Scheduling
Process Burst Time
P
1
P
2
P
3
Suppose that the processes arrive in the order: P
1
The Gantt Chart for the schedule is:
, P
2
, P
3
24
3
3
P
2
P
1
0
Waiting time for P
1
= 0; P
2
= 24; P
3
= 27
Average waiting time: (0 + 24 + 27)/3 = 17
24 27
P
3
30
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition 5.7
Suppose that the processes arrive in the order:
P
2
, P
3
, P
1
The Gantt chart for the schedule is:
P
2
P
3
P
1
0 3 6
Waiting time for P
1
= 6 ; P
2
= 0
;
P
3
= 3
Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case
Convoy effect –
all the processes wait for the one big process to get off the CPU.
30
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition 5.8
None preemptive.
The process that requests CPU first is allocated it first.
FCFS is not good for time sharing.
Operating System Concepts – 8 th Edition 5.9
Silberschatz, Galvin and Gagne ©2009
Shortest job next ( SJN ), also known as Shortest Job First ( SJF ) or Shortest Process Next ( SPN ), is a scheduling policy that selects the waiting process with the smallest execution time to execute next.
[1] SJN is a nonpreemptive algorithm.
SJF is optimal – gives minimum average waiting time for a given set of processes.
Operating System Concepts – 8 th Edition 5.10
Silberschatz, Galvin and Gagne ©2009
Process Arriva
P
1
P
2
P
3
P
4
SJF scheduling chart
P
4 P
1 l Time
0.0
2.0
4.0
5.0
0 3 9
Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
P
3
16
Burst Time
6
8
7
3
P
2
24
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition 5.11
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority (smallest integer
highest priority)
Priority scheduling can be either preemptive or non preemptive
A preemptive priority algorithm will preemptive the CPU if the priority of the newly arrival process is higher than the priority of the currently running process.
Problem
Starvation – low priority processes may never execute
Solution
Aging
Aging A technique of gradually increasing the priority of processes that wait in the system for a long time. This is a solution to the problem of indefinite blockage of low-priority processes.
Operating System Concepts – 8 th Edition 5.12
Silberschatz, Galvin and Gagne ©2009
Example of Priority Scheduling
Process A
P
1
P
2
P
3
P
4
P
5
Priority scheduling Gantt Chart arri Burst Time T
10
1
2
1
5
P
2
P
5
P
1
0 1 6
Average waiting time = 8.2 msec
16
P
3
Priority
3
1
4
5
2
18
P
4
19
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition 5.13
Each process gets a small unit of CPU time ( time quantum q), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
Timer interrupts every quantum to schedule next process
Operating System Concepts – 8 th Edition 5.14
Silberschatz, Galvin and Gagne ©2009
Process
P
1
P
2
P
3
Burst Time
24
3
3
The Gantt chart is:
P
1
0 4 better response
P
2
7
P
3
10
P
1
14
P
1
P
1
18 22
P
1
26
P
1
30
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8 th Edition 5.15
Time Quantum and Context Switch Time
Operating System Concepts – 8 th Edition 5.16
Silberschatz, Galvin and Gagne ©2009