CPU Scheduling - I: Roadmap
CPU Scheduling - I: Roadmap
Fall 2011
• CPU Scheduling
Lecture - V – Basic Concepts
– Scheduling Criteria & Metrics
CPU Scheduling - I – Different Scheduling Algorithms
• FCFS
• SJF
• Priority
• RR
Tevfik Koşar
University at Buffalo
September 13th, 2011 1 2
3 4
5 6
CPU Scheduler Dispatcher
• Selects from among the processes in memory that are ready to
execute, and allocates the CPU to one of them • Dispatcher module gives control of the CPU to the
! short-term scheduler process selected by the short-term scheduler;
• CPU scheduling decisions may take place when a process: Its function involves:
1. Switches from running to waiting state
2. Switches from running to ready state
– switching context
3. Switches from waiting to ready – switching to user mode
4. Terminates – jumping to the proper location in the user program to
5. A new process arrives restart that program
• Scheduling under 1 and 4 is nonpreemptive/cooperative • Dispatch latency – time it takes for the dispatcher
– Once a process gets the CPU, keeps it until termination/switching to to stop one process and start another running
waiting state/release of the CPU
• All other scheduling is preemptive
– Most OS use this
– Cost associated with access to shared data
– i.e. time quota expires
7 8
ta = Tw + Ts D
E
Arrival times
#5 arrived
Tw Ts
A B C D E Mean
Execution times
#5 executed Tr / Ts = 2.5
Tr FCFS scheduling policy Stallings, W. (2004) Operating Systems:
Internals and Design Principles (5th Edition).
11 12
FCFS Scheduling - Example
FCFS Scheduling - Example
Process Burst Time
P1 24 Suppose that the processes arrive in the order
P2 3 P2 , P3 , P1
P3 3 • The Gantt chart for the schedule is:
• Suppose that the processes arrive in the order: P1 ,
P2 , P3 P2 P3 P1
The Gantt Chart for the schedule is:
0 3 6 30
P1 P2 P3
15 16
0 3 7 8 12 16 A B C D E Mean
Process Arrival Time Burst Time • A priority number (integer) is associated with each
P1 0.0 7 process
P2 2.0 4 • The CPU is allocated to the process with the highest
priority (smallest integer ≡ highest priority)
P3 4.0 1 – Preemptive
P4 5.0 4 – nonpreemptive
• SJF (preemptive) Gantt Chart • SJF is a priority scheduling where priority is the
predicted next CPU burst time
P1 P2 P3 P2 P4 P1
• Problem ≡ Starvation – low priority processes may never
11 16
execute
0 2 4 5 7
• Solution ≡ Aging – as time progresses increase the
priority of the process
19 20
A B C D E Mean A B C D E Mean
23 24
Example of RR with Time Quantum = 20 Time Quantum and Context Switch Time
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
Summary Acknowledgements
29 30