Lecture03 Os 13fall
Lecture03 Os 13fall
Operating Systems
Fall 2012
Lecture 4: CPU Scheduling
Assist. Prof. Ediz AYKOL
[email protected]
10/25/2013
CPU Scheduler
Selects from among the processes in ready queue, and
allocates the CPU to one of them
Queue may be ordered in various ways
10/25/2013
Dispatcher
Dispatcher module gives control of the CPU to
the process selected by the short-term
scheduler;
this involves:
switching context
switching to user mode
jumping to the proper location in the user program to
restart/resume that program
Scheduling Criteria
Fairness: each process gets a fair share of the CPU
CPU utilization keep the CPU as busy as possible
Throughput # of processes that complete their execution per time
unit
10/25/2013
Be fair
Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
Conflicting Goals:
Fairness vs Throughput:
Consider a very long job. Should it be run?
10/25/2013
P2
24
P3
27
30
10/25/2013
P3
3
P1
6
30
10/25/2013
10/25/2013
Example of SJF
ProcessArriva l Time
P1
0.0
P2
2.0
P3
4.0
P4
5.0
SJF scheduling Gannt chart
P4
Burst Time
6
8
7
3
P3
P1
3
P2
16
24
10/25/2013
10
Example of Shortest-remaining-time-first
Now we add the concepts of varying arrival times and preemption to the
analysis
ProcessA arri Arrival TimeT
P1
0
P2
1
P3
2
P4
3
Preemptive SJF Gantt Chart
P1
P4
P2
P1
Burst Time
8
4
9
5
10
P3
17
26
10/25/2013
11
Priority Scheduling
A priority number (integer) is associated with each
process
The CPU is allocated to the process with the highest
priority (smallest integer highest priority)
Preemptive
Nonpreemptive
10/25/2013
12
P1
P5
P2
Priority
3
1
4
5
2
P3
16
P4
18
19
13
10/25/2013
14
Burst Time
24
3
3
P2
P3
P1
10
P1
14
P1
18 22
P1
26
P1
30
15
10/25/2013
16
Multilevel Queue
Ready queue is partitioned into separate queues, eg:
foreground (interactive)
background (batch)
17
10/25/2013
18
Scheduling
A new job enters queue Q0 which is served FCFS
10/25/2013
19
10/25/2013
20