Professional Documents
Culture Documents
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Multiple-Processor Scheduling
Operating Systems Examples
Algorithm Evaluation
Basic Concepts
• Maximum CPU utilization obtained with multiprogramming
• CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU
execution and I/O wait
• CPU burst distribution
Scheduling algorithm goals
CPU Scheduler
• Selects from among the processes in memory that are
ready to execute, and allocates the CPU to one of them
• CPU scheduling decisions may take place when a
process:
1.Switches from running to waiting state
2.Switches from running to ready state
3.Switches from waiting to ready
4.Terminates
• Scheduling under 1 and 4 is nonpreemptive
• All other scheduling is preemptive i.e. CPU is taken
forcibly from current process.
Dispatcher Scheduling Criteria
Dispatcher module gives control of the CPU utilization – keep the CPU as busy as
CPU to the process selected by the short- possible
term scheduler; this involves: Throughput – # of processes that
1.switching context complete their execution per time unit
2.switching to user mode Turnaround time – amount of time to
3.jumping to the proper location in execute a particular process
the user program to restart that Waiting time – amount of time a process
program has been waiting in the ready queue
Dispatch latency – time it takes for the Response time – amount of time it takes
dispatcher to stop one process and start from when a request was submitted until
another running the first response is produced, not output
(for time-sharing environment)
Optimization Criteria
• Max CPU utilization
• Max throughput
• Min turnaround time
• Min waiting time
• Min response time
First-Come, First-Served (FCFS) Scheduling
Process Burst time
P1 24
P2 3
P3 3
0 24 27 30
0 3 6 30
• Disadvantages –
– The process with less execution time suffer i.e. waiting time is often quite
long.
– Here, first process will get the CPU first, other processes can get CPU only
after the current process has finished it’s execution. Now, suppose the first
process has large burst time, and other processes have less burst time,
then the processes will have to wait more unnecessarily, this will result
in more average waiting time, i.e., Convoy effect.
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
• SJF (non-preemptive)
• Average waiting time = (0 + 6 + 3 + 7)/4 = 4
P1 P3 P2 P4
0 3 7 8 12 16
Example of Preemptive SJF(SRJF/SRTN)
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
• SJF (preemptive)
• Average waiting time = (9 + 1 + 0 +2)/4 = 3
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
Advantage and disadvantage of
SJF(preemptive and non preemptive
• Advantages –
– Shortest jobs are favored.
– It is provably optimal, in that it gives the minimum
average waiting time for a given set of processes.
• Disadvantages –
– SJF may cause starvation, if shorter processes keep
coming. This problem is solved by aging.
– It cannot be implemented at the level of short
term CPU scheduling.
Determining Length of Next CPU Burst
• Although SJF is optimal but it cannot be applied at the level of short-
term CPU scheduling.
• There is no way to know the length of the next CPU burst.
• One approach is to approximate SJF scheduling.
• We may not be able to know next CPU burst but we may be able to
predict its value.
• We expect that the next CPU burst will be similar in length to the
previous ones.
• Let tn be the length of nth CPU burst, let τn+1 be our predicted value
for the next CPU burst. Then for α , 0≤ α ≤ 1 ,define
If a process with higher priority than the Once resources are allocated to a process, the
process currently being executed arrives, the process holds it till it completes its burst time
CPU is preemeted and given to the higher even if a process with higher priority is added
priority process. to the queue.
The waiting time for the process having the The waiting time for the process having the
highest priority will always be zero. highest priority may not be zero.
It is more expensive and difficult to implement. It is cheaper to implement and faster as less
Also a lot of time is wasted in switching. switching is required.
It is useful in applications where high priority It can be used in various hardware applications
processes cannot be kept waiting. where waiting will not cause any serious
issues.
Example of NON-PREEMPTIVE Priority Scheduling
1. There is fairness since every process There is Larger waiting time and
gets equal share of CPU. Response time.
4. While performing a round-robin Gantt chart seems to come too big (if
scheduling, a particular time quantum is quantum time is less for scheduling .For
alloted to different jobs. Example:1 ms for big scheduling.)
5. Each process get a chance to reschedule Time consuming scheduling for small
after a particular quantum time in this quantums .
scheduling.
ROUND ROBIN Scheduling Example
ROUND ROBIN Scheduling Example
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3