Professional Documents
Culture Documents
Scheduling
• Processes in different state maintain Queues.
• The different queues are maintained for different purpose
eg.
– Ready Queue : Processes waiting for CPU
– Blocked : processes waiting for I/O to complete
• Transition from a state where queue is maintained to next
state involves decision making such as
– When to move process from one state to another
– Which process to move
• When transitions occur, OS may be required to carry out
some house keeping activity such as context switch,
Mode switch etc. These activities are considered as
overhead and must be carried out in efficient manner
• Scheduling is matter of managing queues to minimize
queuing delay and to optimize performance in queuing
environment
• Scheduling affects the performance of the system
because it determines which process will wait and which
will progress
7 States
Types of Scheduling
Long-term Scheduling
• Long-term scheduler is invoked very infrequently
(seconds, minutes) (may be slow). Invoked to move a
new process to ready or ready suspend queue
• Determines which programs are admitted to the system
for processing
• Controls the degree of multiprogramming
Long-term Scheduling
•More processes=> smaller percentage of time each
process is executed
•Processes can be described as either:
– I/O-bound process – spends more time doing I/O than
computations; very short CPU bursts.
– CPU-bound process – spends more time doing
computations; very long CPU bursts.
Basic Concepts
•Maximum CPU Utilization Obtained With Multiprogramming
•Process Execution Consists of a Cycle of CPU Execution
and I/O Wait. => CPU–I/O Burst Cycle
•CPU Burst Distribution – Processes Mostly Have Short CPU
Bursts (~5ms)
Alternating Sequence of CPU And I/O Bursts
Histogram of CPU-burst Times
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible
• Throughput – # of processes that complete their
execution per time unit
• Turnaround time – amount of time taken to complete a
particular process from its submission to its termination.
Also known as residence time Tr.
– The actual CPU time taken by a process is called
Service time, Ts. The Normalized turnaround time is
then defined as Tr/Ts. Minimum possible value is 1,
which means immediate service.
• Priorities- can be fixed in many ways
Scheduling Criteria
• 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, not output (for time-sharing environment)
• Predictability – keep the variance of response time low
under different load conditions
• Fairness- Provide equal share of CPU time to all
workgroups
Optimization Criteria
In short:
• Max CPU utilization
• Max throughput
• Max predictability
• Min turnaround time
• Min waiting time
• Min response time
First-come, First-served (FCFS) Scheduling
• Example: Process Burst Time
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
0 3 6 30
• Waiting time for P1 = 6; P2 = 0; P3 = 3
• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case.
• Convoy effect short process behind long process => FCFS
penalizes short processes
First-come-first-served (FCFS)
0 3 7 8 12 16
0 2 4 5 7 11 16
• Average waiting time = (9 + 1 + 0 +2)/4 =3
Determining Length of Next CPU Burst
•Rule of thumb: time quantum should be slightly larger than the time
required for a typical interaction. also the time quantum should be
about 10 times larger than the context switch time
•RR is unfair to I/O bound processes=> Use Virtual RR(VRR) with
an auxiliary queue
Operating System Concepts
Turnaround Time Varies With The Time Quantum
Process Scheduling Example for HRRN
Highest Response Ratio Next (HRRN)
0 5 10 15 20
1
2
3
4
5
• Choose next process with the highest ratio (normalized
turnaround time)
time spent waiting + expected service time
expected service time