OPERATING SYSTEM:CPU SCHEDULING
• Dr Vatan sehrawat
• Asst. Professor, Computer Science & engg dept.
• RPSCET, Balana, Mahendragarh
• vatansehrawat@gmail.com
• 8059211113
It is the change of ready state to running state of the
process. CPU scheduler selects process among the processes
that are ready to execute and allocates CPU to one of them.
Short term scheduler also known as dispatcher, execute most
frequently and makes the fine grained decision of which
process to execute next.
CPU scheduling decisions may take place when a process:
Switches from running to waiting state.
Switches from running to ready state.
Switches from waiting to ready.
Terminates
Scheduling Criteria
Criteria for best scheduling algorithm:
CPU Utilization : Computer usage of memory and processing
resources or amount of work handle by a CPU.
Throughput : It is the total number of process completed per unit
time.
Load average : average number of processes sitting in the
ready queue waiting for that turn to get onto CPU.
Fairness : All the jobs should get fair chance to get the use of
CPU.
Efficiency : scheduler should keep the system busy whole time, if
CPU and all i/o devices can be kept running all the time more
work can be done per second.
Response / service time : Amount of time taken from when a request was
submitted until first response is produced is called response / service
time.
Response time = Time at which the process gets the CPU for the first time - Arrival
time
Turn around time : It is the total amount of time the process executed itself
on the CPU.
Turnaround time = Burst time + Waiting time
Turnaround time = Exit time - Arrival time
Waiting time : It is the amount of time a process waits to load itself on the
CPU.
Waiting time = Turnaround time - Burst time
Waiting Time = Service Time - Arrival Time
Arrival Time: Time at which the process arrives in the ready queue.
Completion Time: Time at which process completes its execution.
Burst Time: Time required by a process for CPU execution.
Scheduling Objectives
When to schedule :
• When a new process is created , a decision needs to be made whether to run the
parent process or child process.
• A scheduling decision must be made when a process exits.
• When I/O interrupt occurs , a scheduling decision may be made.
Main objective of scheduling is :
• Be Fair
• Make the system fast
• Maximize throughput
• Increasing the profit.
• Increasing the output.
• Maximize number of users receiving acceptible response times.
• Reducing the manufacturing time.
• Minimizing the production costs
• Give better service to processes that have desirable behaviour patterns
Schedul
er
• When a computer is multiprogrammed , it frequently
has multiple process or threads competing for the CPU at
the same time.
• This situation occurs whenever two or more of them
are simultaneously in the ready state.
• If only one CPU is available , a choice has to be
made which process to run next.
• The part of the operating system that makes the choice
is called the scheduler.
Types of
schedulers
Schedulers are of 3 types :
1. Long term scheduler
2. Short term scheduler
3. Medium term scheduler
Long term
schedulers
• It is also called job scheduler
• It determine which program are admitted to a system
for processing .
• It selects process from queue and loads them in to memory
for execution .
• On some system it may not me available or may be minimal .
• Time sharing operating systems have no long term scheduler.
• When process changes the state from new to ready, then there
is use of long term scheduler.
Short term
schedulers
• It is also called CPU scheduler.
• Main objective is increasing system performance in accordance
with the chosen set of criteria .
• CPU scheduler selects process among the processes that are ready
to execute and allocates CPU to one of them.
• When process changes the state from ready to running, then there
is use of long term scheduler.
• They are also called as dispatchers.
• Context switching is done by dispatchers.
• Faster than long term schedulers .
 Dispatchers :
• It gives control of CPU to the process selected by short
term scheduler.
• This involves switching context , switching of user mode
, jumping to proper location in the user program to
restart that program .
 Dispatcher latency :
• Time taken by dispatcher to stop one process and
start another .
Medium term schedulers
• It is the part of swapping .
• It removes the processes from memory .
• A running process may become suspended if it does not
get I/O resource needed.
• In this condition the process is move to the
secondary storage until it gets the resources.
• It is the part of time sharing operating system.
Comparison among Scheduler
Maximum CPU utilization.
Max throughput.
Minimum turn around time.
Minimum waiting time.
Minimum response time
• First Come First Serve (FCFS) Scheduling
• Shortest-Job-First (SJF) Scheduling
• Priority Scheduling
• Round Robin(RR) Scheduling
• Multilevel Queue Scheduling
First-Come ,First-Served(FCFS)Scheduling
Since CPU gets a lot of processes to handle. So in
FCFS CPU will take the first process in the list and
will process it then it will take the second process
and so on. For example let there be three processes:
PROCESSES BURSTS TIME
P1 24
P2 3
P3 3
Suppose that the processes arrive in order p1,p2,p3
So the waiting time for p1=0,p2=24,p3=27
The average waiting time=(0+24+27)/3=17.
One of the major drawback of this scheme is that the
Average waiting time is often quite long.
It is best approach to minimize waiting time. it
Selects the waiting process with the smallest
execution time to execute next.
Processes Bursts time
P1 6
P2 8
P3 7
P4 3
Average waiting time=(3+16+9+0)/4=7.
The disadvantage of using SJF is that the total
execution time of a job must be known before
execution. while it is not possible to perfectly
predict execution time.
Priority scheduling is a method of scheduling
processes based on priority. In this method the
scheduler chooses the tasks to work as per the
priority.
Processes Burst time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Average waiting time=(6+0+16+18+1)/5=8.2
The drawback of priority scheduling is starvation
of low priority process.
In the round robin scheduling, processes are
dispatched in a FIFO manner but are given a
limited amount of CPU time called a time-slice
or a quantum.
If a process does not complete before its CPU-time
expires, the CPU is preempted and given to the
next process waiting in a queue. The preempted
process is then placed at the back of the ready
list.
A CPU Scheduling Mechanism Should
• Favour short jobs.
• Favour I/O bound jobs to get good I/O device
utilization.
• Determine the nature of a job and schedule
accordingly.
topic cpu scheduling in operating system.pptx

topic cpu scheduling in operating system.pptx

  • 1.
    OPERATING SYSTEM:CPU SCHEDULING •Dr Vatan sehrawat • Asst. Professor, Computer Science & engg dept. • RPSCET, Balana, Mahendragarh • vatansehrawat@gmail.com • 8059211113
  • 2.
    It is thechange of ready state to running state of the process. CPU scheduler selects process among the processes that are ready to execute and allocates CPU to one of them. Short term scheduler also known as dispatcher, execute most frequently and makes the fine grained decision of which process to execute next. CPU scheduling decisions may take place when a process: Switches from running to waiting state. Switches from running to ready state. Switches from waiting to ready. Terminates
  • 3.
    Scheduling Criteria Criteria forbest scheduling algorithm: CPU Utilization : Computer usage of memory and processing resources or amount of work handle by a CPU. Throughput : It is the total number of process completed per unit time. Load average : average number of processes sitting in the ready queue waiting for that turn to get onto CPU. Fairness : All the jobs should get fair chance to get the use of CPU. Efficiency : scheduler should keep the system busy whole time, if CPU and all i/o devices can be kept running all the time more work can be done per second.
  • 4.
    Response / servicetime : Amount of time taken from when a request was submitted until first response is produced is called response / service time. Response time = Time at which the process gets the CPU for the first time - Arrival time Turn around time : It is the total amount of time the process executed itself on the CPU. Turnaround time = Burst time + Waiting time Turnaround time = Exit time - Arrival time Waiting time : It is the amount of time a process waits to load itself on the CPU. Waiting time = Turnaround time - Burst time Waiting Time = Service Time - Arrival Time Arrival Time: Time at which the process arrives in the ready queue. Completion Time: Time at which process completes its execution. Burst Time: Time required by a process for CPU execution.
  • 5.
    Scheduling Objectives When toschedule : • When a new process is created , a decision needs to be made whether to run the parent process or child process. • A scheduling decision must be made when a process exits. • When I/O interrupt occurs , a scheduling decision may be made. Main objective of scheduling is : • Be Fair • Make the system fast • Maximize throughput • Increasing the profit. • Increasing the output. • Maximize number of users receiving acceptible response times. • Reducing the manufacturing time. • Minimizing the production costs • Give better service to processes that have desirable behaviour patterns
  • 6.
    Schedul er • When acomputer is multiprogrammed , it frequently has multiple process or threads competing for the CPU at the same time. • This situation occurs whenever two or more of them are simultaneously in the ready state. • If only one CPU is available , a choice has to be made which process to run next. • The part of the operating system that makes the choice is called the scheduler.
  • 7.
    Types of schedulers Schedulers areof 3 types : 1. Long term scheduler 2. Short term scheduler 3. Medium term scheduler
  • 8.
    Long term schedulers • Itis also called job scheduler • It determine which program are admitted to a system for processing . • It selects process from queue and loads them in to memory for execution . • On some system it may not me available or may be minimal . • Time sharing operating systems have no long term scheduler. • When process changes the state from new to ready, then there is use of long term scheduler.
  • 9.
    Short term schedulers • Itis also called CPU scheduler. • Main objective is increasing system performance in accordance with the chosen set of criteria . • CPU scheduler selects process among the processes that are ready to execute and allocates CPU to one of them. • When process changes the state from ready to running, then there is use of long term scheduler. • They are also called as dispatchers. • Context switching is done by dispatchers. • Faster than long term schedulers .
  • 10.
     Dispatchers : •It gives control of CPU to the process selected by short term scheduler. • This involves switching context , switching of user mode , jumping to proper location in the user program to restart that program .  Dispatcher latency : • Time taken by dispatcher to stop one process and start another .
  • 11.
    Medium term schedulers •It is the part of swapping . • It removes the processes from memory . • A running process may become suspended if it does not get I/O resource needed. • In this condition the process is move to the secondary storage until it gets the resources. • It is the part of time sharing operating system.
  • 12.
  • 13.
    Maximum CPU utilization. Maxthroughput. Minimum turn around time. Minimum waiting time. Minimum response time
  • 14.
    • First ComeFirst Serve (FCFS) Scheduling • Shortest-Job-First (SJF) Scheduling • Priority Scheduling • Round Robin(RR) Scheduling • Multilevel Queue Scheduling
  • 15.
    First-Come ,First-Served(FCFS)Scheduling Since CPUgets a lot of processes to handle. So in FCFS CPU will take the first process in the list and will process it then it will take the second process and so on. For example let there be three processes: PROCESSES BURSTS TIME P1 24 P2 3 P3 3
  • 16.
    Suppose that theprocesses arrive in order p1,p2,p3 So the waiting time for p1=0,p2=24,p3=27 The average waiting time=(0+24+27)/3=17. One of the major drawback of this scheme is that the Average waiting time is often quite long.
  • 17.
    It is bestapproach to minimize waiting time. it Selects the waiting process with the smallest execution time to execute next. Processes Bursts time P1 6 P2 8 P3 7 P4 3
  • 18.
    Average waiting time=(3+16+9+0)/4=7. Thedisadvantage of using SJF is that the total execution time of a job must be known before execution. while it is not possible to perfectly predict execution time.
  • 19.
    Priority scheduling isa method of scheduling processes based on priority. In this method the scheduler chooses the tasks to work as per the priority. Processes Burst time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2
  • 20.
    Average waiting time=(6+0+16+18+1)/5=8.2 Thedrawback of priority scheduling is starvation of low priority process.
  • 21.
    In the roundrobin scheduling, processes are dispatched in a FIFO manner but are given a limited amount of CPU time called a time-slice or a quantum. If a process does not complete before its CPU-time expires, the CPU is preempted and given to the next process waiting in a queue. The preempted process is then placed at the back of the ready list.
  • 22.
    A CPU SchedulingMechanism Should • Favour short jobs. • Favour I/O bound jobs to get good I/O device utilization. • Determine the nature of a job and schedule accordingly.