Chapter 5 Slides
Chapter 5 Slides
LE QUOC HUY
! 5.1. Basic Concepts
! 5.2. Scheduling Criteria
! 5.3. Scheduling Algorithms
! 5.4. Thread Scheduling
! 5.5. Multi-Processor Scheduling
of Chapter 5 ! 5.7. Operating Systems
Examples
Several processes are kept in memory at one
time.
When one process has to wait, the operating
system takes the CPU away from that process
and gives the CPU to another process.
Almost all computer resources are scheduled
before use
An I/O-bound
program typically
has many short CPU
bursts.
A CPU-bound
program might have
a few long CPU
Large number of short bursts bursts.
Small number of longer bursts
! …selects from among the processes in ready
queue, and allocates a CPU core to one of them
! Ready queue may be ordered in various ways:
• FIFO queue,
• a priority queue,
• a tree,
• an unordered linked
list.
! CPU scheduling decisions may take place
when a process:
1. Running state to waiting state
2. Running state to ready state
3. Waiting state to ready state
4. Terminates
! Scheduling under 1 and 4 is nonpreemptive
! All other scheduling is preemptive
! Consider access to shared data
! Consider preemption while in kernel mode
! Consider interrupts occurring during crucial
OS activities
…gives control of the CPU to the
process selected by the CPU scheduler.
…involves:
! switching context
! switching to user mode
! jumping to the proper location in
the user program to restart that
program
! Dispatch latency – time it takes for
the dispatcher to stop one process
and start another running
! CPU utilization – keep the CPU as busy as possibleè Maximize
! Throughput – # of processes that complete their execution per
time unit è Maximize
! Turnaround time – amount of time to execute a particular
process è Minimize
! Waiting time – amount of time a process has been waiting in
the ready queue è Minimize
! 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) è Minimize
• the process that requests the CPU first is
allocated the CPU first.
• The implementation of the FCFS policy is easily
managed with a FIFO queue.
• When a process enters the ready queue, its
PCB is linked onto the tail of the queue. When
the CPU is free, it is allocated to the process at
the head of the queue.
Gantt chart Process Burst Time (milisecond)
P1 24
P2 3
P3 3
! Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
P1 P2 P3
0 24 27 30
! Gann chart P4 P1 P3 P2
0 3 9 16 24
SJF, (or P3 2 9
Shortest- P4 3 5
time-first) P1 P2 P4 P1 P3
0 1 5 10 17 26
0 4 7 10 14 18 22 26 30
! Nonpreemptive
! SJF is priority scheduling where priority is the inverse of
predicted next CPU burst time
! Equal-priority processes are scheduled in FCFS order
! Problem: Starvation – low priority processes may never
execute
! Solution: Aging – as time progresses increase the priority of
the process
Example of Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
P1 P2 P3 P4 P3 P5 P4 P6 P3 P4 P2
0 15 20 30 40 45 50 55 70 75 80 95
being scheduled
using a
preemptive,
priority-based,
round-robin
Soft Hard
affinity affinity