SlideShare a Scribd company logo
Scheduling
Algorithm
Raj Vardhan
CPU
scheduling
CPU scheduling is the process of deciding which process will
own the CPU to use while another process is suspended. The
main function of the CPU scheduling is to ensure that
whenever the CPU remains idle, the OS has at least selected
one of the processes available in the ready-to-use line.
In Multiprogramming, if the long-term scheduler selects
multiple I / O binding processes then most of the time, the
CPU remains an idle. The function of an effective program is
to improve resource utilization.
If most operating systems change their status from
performance to waiting then there may always be a chance
of failure in the system. So in order to minimize this excess,
the OS needs to schedule tasks in order to make full use of
the CPU and avoid the possibility of deadlock.
Objectives of
Process
Scheduling
Algorithm
Utilization of CPU at maximum level. Keep CPU as busy as
possible.
Allocation of CPU should be fair.
Throughput should be Maximum. i.e. Number of processes
that complete their execution per time unit should be
maximized.
Minimum turnaround time, i.e. time taken by a process to
finish execution should be the least.
There should be a minimum waiting time and the process
should not starve in the ready queue.
Minimum response time. It means that the time when a
process produces the first response should be as less as
possible.
Terminologie
s in any CPU
Scheduling
algorithm?
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.
Turn Around Time: Time Difference between
completion time and arrival time.
Waiting Time(W.T): Time Difference between
turn around time and burst time.
Conditions in
CPU
Scheduling
algorithm
CPU utilization: The main purpose of any CPU algorithm is to keep the CPU as busy as
possible. Theoretically, CPU usage can range from 0 to 100 but in a real-time system, it
varies from 40 to 90 percent depending on the system load.
Throughput: The average CPU performance is the number of processes performed and
completed during each unit. This is called throughput. The output may vary depending
on the length or duration of the processes.
Turn round Time: For a particular process, the important conditions are how long it
takes to perform that process. The time elapsed from the time of process delivery to
the time of completion is known as the conversion time. Conversion time is the amount
of time spent waiting for memory access, waiting in line, using CPU, and waiting for I /
O.
Waiting Time: The Scheduling algorithm does not affect the time required to complete
the process once it has started performing. It only affects the waiting time of the
process i.e. the time spent in the waiting process in the ready queue.
Response Time: In a collaborative system, turn around time is not the best option. The
process may produce something early and continue to computing the new results
while the previous results are released to the user. Therefore another method is the
time taken in the submission of the application process until the first response is
issued. This measure is called response time.
Different
types of CPU
Scheduling
Algorithms
 Preemptive Scheduling: Preemptive scheduling is used
when a process switches from running state to ready
state or from the waiting state to the ready state.
 Non-Preemptive Scheduling: Non-Preemptive scheduling
is used when a process terminates , or when a process
switches from running state to waiting state.
Scheduling Algorithm in System Designing.pptx
First Come
First Serve
(FCFS)
FCFS considered to be the simplest of all operating system
scheduling algorithms. First come first serve scheduling
algorithm states that the process that requests the CPU first
is allocated the CPU first and is implemented by using FIFO
queue.
Characteristics of FCFS:
• FCFS supports non-preemptive and preemptive CPU scheduling algorithms.
• Tasks are always executed on a First-come, First-serve concept.
• FCFS is easy to implement and use.
• This algorithm is not much efficient in performance, and the wait time is
quite high.
Advantages of FCFS:
• Easy to implement
• First come, first serve method
Disadvantages of FCFS:
• FCFS suffers from Convoy effect.
• The average waiting time is much higher than the other algorithms.
• FCFS is very simple and easy to implement and hence not much efficient.
Process
Wait Time : Service Time - Arrival
Time
P0 0 - 0 = 0
P1 5 - 1 = 4
P2 8 - 2 = 6
P3 16 - 3 = 13
Average Wait Time: (0+4+6+13) / 4 = 5.75
Shortest Job
First (SJF)
Shortest job first (SJF) is a scheduling process that selects the waiting
process with the smallest execution time to execute next. This
scheduling method may or may not be preemptive. Significantly
reduces the average waiting time for other processes waiting to be
executed. The full form of SJF is Shortest Job First.
Characteristics of SJF:
• Shortest Job first has the advantage of having a minimum average waiting time among
all operating system scheduling algorithms.
• It is associated with each task as a unit of time to complete.
• It may cause starvation if shorter processes keep coming. This problem can be solved
using the concept of ageing.
Advantages of Shortest Job first:
• As SJF reduces the average waiting time thus, it is better than the first come first serve
scheduling algorithm.
• SJF is generally used for long term scheduling
Disadvantages of SJF:
• One of the demerit SJF has is starvation.
• Many times it becomes complicated to predict the length of the upcoming CPU request
Process Waiting Time
P0 0 - 0 = 0
P1 5 - 1 = 4
P2 14 - 2 = 12
P3 8 - 3 = 5
Average Wait Time: (0 + 4 + 12 + 5)/4 = 21 / 4 = 5.25
Longest Job
First(LJF)
Longest Job First(LJF) scheduling process is just opposite of
shortest job first (SJF), as the name suggests this algorithm is
based upon the fact that the process with the largest burst time
is processed first. Longest Job First is non-preemptive in nature.
Characteristics of LJF:
• Among all the processes waiting in a waiting queue, CPU is always assigned to the
process having largest burst time.
• If two processes have the same burst time then the tie is broken using FCFS i.e.
the process that arrived first is processed first.
• LJF CPU Scheduling can be of both preemptive and non-preemptive types.
Advantages of LJF:
• No other task can schedule until the longest job or process executes completely.
• All the jobs or processes finish at the same time approximately.
Disadvantages of LJF:
• Generally, the LJF algorithm gives a very high average waiting time and average
turn-around time for a given set of processes.
• This may lead to convoy effect.
Process Arrival Time Burst Time Completion
Time
Turn around
Time =
Completion
Time – Arrival
Time
Waiting Time
= Turn Around
Time – Burst
Time
P1 1 2 3 3-1=2 2-2=0
P2 2 5 8 8-2=6 6-5=1
P3 3 3 19 19-3=16 16-3=13
P4 4 8 16 16-4=12 12-8=4
Total Turn Around Time = 36 ms
So, Average Turn Around Time = 36/4 = 9.00 ms
And, Total Waiting Time = 18 ms
So, Average Waiting Time = 18/4 = 4.5 ms
Highest
Response
Ratio Next
Highest Response Ratio Next is a non-preemptive CPU Scheduling
algorithm and it is considered as one of the most optimal scheduling
algorithms. The name itself states that we need to find the response ratio
of all available processes and select the one with the highest Response
Ratio. A process once selected will run till completion.
Characteristics of Highest Response Ratio Next:
• The criteria for HRRN is Response Ratio, and the mode is Non-Preemptive.
• HRRN is considered as the modification of Shortest Job First to reduce the problem of
starvation.
• In comparison with SJF, during the HRRN scheduling algorithm, the CPU is allotted to the next
process which has the highest response ratio and not to the process having less burst time.
• Response Ratio = (W + S)/S Here, W is the waiting time of the process so far and S is the Burst
time of the process.
Advantages of HRRN:
• HRRN Scheduling algorithm generally gives better performance than the shortest job first
Scheduling.
• There is a reduction in waiting time for longer jobs and also it encourages shorter jobs.
Disadvantages of HRRN:
• The implementation of HRRN scheduling is not possible as it is not possible to know the burst
time of every job in advance.
• In this scheduling, there may occur an overload on the CPU.
Processes Arrival time Burst Time
P1 0ms 3ms
P2 2ms 6ms
P3 4ms 4ms
P4 6ms 5ms
P5 8ms 2ms
Processes Arrival time Burst Time
Completion
Time
Turn Around
Time
Wait Time
P1 0 3 3 3-0 = 3 3-3 = 0
P2 2 6 9 9-2 = 7 7-6 = 1
P3 4 4 13 13-4 = 9 9-4 = 5
P4 6 5 20 20-6 = 14 14-5 = 9
P5 8 2 15 15-8 = 7 7-2 = 5
Total Turn Around Time = 40 ms
So, Average Turn Around Time = 40/5 = 8.00 ms
And, Total Waiting Time = 20 ms
So, Average Waiting Time = 20/5 = 4.00 ms
Turn Around Time = Completion Time – Arrival Time
Waiting Time = Turn Around Time – Burst Time
Priority
Scheduling
Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method of
CPU scheduling algorithm that works based on the priority of a process. In
this algorithm, the editor sets the functions to be as important, meaning
that the most important process must be done first. In the case of any
conflict, that is, where there are more than one processor with equal
value, then the most important CPU planning algorithm works on the
basis of the FCFS (First Come First Serve) algorithm.
Characteristics of Priority Scheduling:
• Schedules tasks based on priority.
• When the higher priority work arrives while a task with less priority is executed, the higher
priority work takes the place of the less priority one.
• The latter is suspended until the execution is complete.
• Lower is the number assigned, higher is the priority level of a process.
Advantages of Priority Scheduling:
• The average waiting time is less than FCFS
• Less complex
Disadvantages of Priority Scheduling:4
• One of the most common demerits of the Preemptive priority CPU scheduling algorithm is the
Starvation Problem. This is the problem in which a process has to wait for a longer amount of
time to get scheduled into the CPU. This condition is called the starvation problem.
Process Waiting Time
P0 0 - 0 = 0
P1 11 - 1 = 10
P2 14 - 2 = 12
P3 5 - 3 = 2
Average Wait Time: (0 + 10 + 12 + 2)/4 = 24 / 4 = 6
Round Robin
 Round Robin is a CPU scheduling algorithm where each
process is cyclically assigned a fixed time slot. It is the
preemptive version of First come First Serve CPU Scheduling
algorithm. Round Robin CPU Algorithm generally focuses on
Time Sharing technique.
 Characteristics of Round robin
 It’s simple, easy to use, and starvation-free as all processes get
the balanced CPU allocation.
 One of the most widely used methods in CPU scheduling as a
core.
 It is considered preemptive as the processes are given to the CPU
for a very limited time.
 Advantages of Round robin
 Round robin seems to be fair as every process gets an equal
share of CPU.
 The newly created process is added to the end of the ready
queue.
Process
Wait Time : Service Time - Arrival
Time
P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P2 (6 - 2) + (14 - 9) + (20 - 17) = 12
P3 (9 - 3) + (17 - 12) = 11
Average Wait Time: (9+2+12+11) / 4 = 8.5
Shortest
Remaining
Time First
 Shortest remaining time first is the preemptive version of the Shortest
job first which we have discussed earlier where the processor is
allocated to the job closest to completion. In SRTF the process with the
smallest amount of time remaining until completion is selected to
execute.
 Characteristics of Shortest remaining time first:
 SRTF algorithm makes the processing of the jobs faster than SJF
algorithm, given it’s overhead charges are not counted.
 The context switch is done a lot more times in SRTF than in SJF and
consumes the CPU’s valuable time for processing. This adds up to its
processing time and diminishes its advantage of fast processing.
 Advantages of SRTF:
 In SRTF the short processes are handled very fast.
 The system also requires very little overhead since it only makes a
decision when a process completes or a new process is added.
 Disadvantages of SRTF:
 Like the shortest job first, it also has the potential for process starvation.
 Long processes may be held off indefinitely if short processes are
continually added.
Process Completion
Time
Turn Around
Time
Waiting Time
P1 15 15-2 = 13 13-6 = 7
P2 7 7-5 = 2 2-2 = 0
P3 23 23-1 = 22 22-8 = 14
P4 3 3-0 = 3 3-3 = 0
P5 10 10-4 = 6 6-4 = 2
•Average Turn around time = (13 + 2 + 22 + 3 + 6)/5 = 9.2
•Average waiting time = (7 + 0 + 14 + 0 + 2)/5 = 23/5 = 4.6
Longest
Remaining
Time First
 The longest remaining time first is a preemptive version of the longest
job first scheduling algorithm. This scheduling algorithm is used by the
operating system to program incoming processes for use in a
systematic way. This algorithm schedules those processes first which
have the longest processing time remaining for completion.
 Characteristics of longest remaining time first:
 Among all the processes waiting in a waiting queue, the CPU is always
assigned to the process having the largest burst time.
 If two processes have the same burst time then the tie is broken using
FCFS i.e. the process that arrived first is processed first.
 LJF CPU Scheduling can be of both preemptive and non-preemptive types.
 Advantages of LRTF:
 No other process can execute until the longest task executes completely.
 All the jobs or processes finish at the same time approximately.
 Disadvantages of LRTF:
 This algorithm gives a very high average waiting time and average turn-
around time for a given set of processes.
 This may lead to a convoy effect.
Processes Arrival Time Burst Time
P1 0ms 2ms
P2 0ms 3ms
P3 2ms 2ms
P4 3ms 5ms
P5 4ms 4ms
Turn Around Time (TAT)
= (Completion Time) – (Arrival Time)
Also, Waiting Time (WT)
= (Turn Around Time) – (Burst Time)

More Related Content

PPT
Ch05 cpu-scheduling
PPT
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
PPTX
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
PDF
Operating System-Process Scheduling
PDF
Unit iios process scheduling and synchronization
PPT
Process management in os
PPTX
operating system scheduling concept lec2
DOC
Operating Systems Third Unit - Fourth Semester - Engineering
Ch05 cpu-scheduling
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
Operating System-Process Scheduling
Unit iios process scheduling and synchronization
Process management in os
operating system scheduling concept lec2
Operating Systems Third Unit - Fourth Semester - Engineering

Similar to Scheduling Algorithm in System Designing.pptx (20)

PDF
CPU Scheduling
PPTX
Osy ppt - Copy.pptx
PDF
OS Process Chapter 3.pdf
PPT
MODULE 2 for the cpu shcheduling and.ppt
PPT
Introduction of cpu scheduling in operating system
PPTX
Preemptive process example.pptx
PPT
Cpu scheduling
PPT
Operating System 5
PPTX
CPU scheduling
PPTX
Cpu scheduling
PPTX
3Chapter Three- CPU Scheduling this is the best.pptx
PPTX
CPU Scheduling.pptx this is operating system
PDF
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
PPT
Unit2 CPU Scheduling 24252 (sssssss1).ppt
PPT
Unit2 CPU Scheduling 24252.ppBBBBBBBBBBt
PDF
Fcfs and sjf
PDF
cpu schduling ppt.pdf
PPTX
UNIPROCESS SCHEDULING.pptx
PPTX
Operating system
PPT
OS-operating systems- ch05 (CPU Scheduling) ...
CPU Scheduling
Osy ppt - Copy.pptx
OS Process Chapter 3.pdf
MODULE 2 for the cpu shcheduling and.ppt
Introduction of cpu scheduling in operating system
Preemptive process example.pptx
Cpu scheduling
Operating System 5
CPU scheduling
Cpu scheduling
3Chapter Three- CPU Scheduling this is the best.pptx
CPU Scheduling.pptx this is operating system
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
Unit2 CPU Scheduling 24252 (sssssss1).ppt
Unit2 CPU Scheduling 24252.ppBBBBBBBBBBt
Fcfs and sjf
cpu schduling ppt.pdf
UNIPROCESS SCHEDULING.pptx
Operating system
OS-operating systems- ch05 (CPU Scheduling) ...
Ad

More from errvmaurya563 (6)

PPTX
Memory Management in System Designing.pptx
PPTX
Database Management System PART- II.pptx
PPTX
Database Management System Introduction to DBMS.pptx
PPTX
Principle Components Analysis Machine Learning.pptx
PPTX
HTTP_Common_Request_Methods_Presentation.pptx
PPTX
Error Detection in Data link layer or Transport layer
Memory Management in System Designing.pptx
Database Management System PART- II.pptx
Database Management System Introduction to DBMS.pptx
Principle Components Analysis Machine Learning.pptx
HTTP_Common_Request_Methods_Presentation.pptx
Error Detection in Data link layer or Transport layer
Ad

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Microbial disease of the cardiovascular and lymphatic systems
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O5-L3 Freight Transport Ops (International) V1.pdf
Basic Mud Logging Guide for educational purpose
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Insiders guide to clinical Medicine.pdf
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
human mycosis Human fungal infections are called human mycosis..pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester

Scheduling Algorithm in System Designing.pptx

  • 2. CPU scheduling CPU scheduling is the process of deciding which process will own the CPU to use while another process is suspended. The main function of the CPU scheduling is to ensure that whenever the CPU remains idle, the OS has at least selected one of the processes available in the ready-to-use line. In Multiprogramming, if the long-term scheduler selects multiple I / O binding processes then most of the time, the CPU remains an idle. The function of an effective program is to improve resource utilization. If most operating systems change their status from performance to waiting then there may always be a chance of failure in the system. So in order to minimize this excess, the OS needs to schedule tasks in order to make full use of the CPU and avoid the possibility of deadlock.
  • 3. Objectives of Process Scheduling Algorithm Utilization of CPU at maximum level. Keep CPU as busy as possible. Allocation of CPU should be fair. Throughput should be Maximum. i.e. Number of processes that complete their execution per time unit should be maximized. Minimum turnaround time, i.e. time taken by a process to finish execution should be the least. There should be a minimum waiting time and the process should not starve in the ready queue. Minimum response time. It means that the time when a process produces the first response should be as less as possible.
  • 4. Terminologie s in any CPU Scheduling algorithm? 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. Turn Around Time: Time Difference between completion time and arrival time. Waiting Time(W.T): Time Difference between turn around time and burst time.
  • 5. Conditions in CPU Scheduling algorithm CPU utilization: The main purpose of any CPU algorithm is to keep the CPU as busy as possible. Theoretically, CPU usage can range from 0 to 100 but in a real-time system, it varies from 40 to 90 percent depending on the system load. Throughput: The average CPU performance is the number of processes performed and completed during each unit. This is called throughput. The output may vary depending on the length or duration of the processes. Turn round Time: For a particular process, the important conditions are how long it takes to perform that process. The time elapsed from the time of process delivery to the time of completion is known as the conversion time. Conversion time is the amount of time spent waiting for memory access, waiting in line, using CPU, and waiting for I / O. Waiting Time: The Scheduling algorithm does not affect the time required to complete the process once it has started performing. It only affects the waiting time of the process i.e. the time spent in the waiting process in the ready queue. Response Time: In a collaborative system, turn around time is not the best option. The process may produce something early and continue to computing the new results while the previous results are released to the user. Therefore another method is the time taken in the submission of the application process until the first response is issued. This measure is called response time.
  • 6. Different types of CPU Scheduling Algorithms  Preemptive Scheduling: Preemptive scheduling is used when a process switches from running state to ready state or from the waiting state to the ready state.  Non-Preemptive Scheduling: Non-Preemptive scheduling is used when a process terminates , or when a process switches from running state to waiting state.
  • 8. First Come First Serve (FCFS) FCFS considered to be the simplest of all operating system scheduling algorithms. First come first serve scheduling algorithm states that the process that requests the CPU first is allocated the CPU first and is implemented by using FIFO queue. Characteristics of FCFS: • FCFS supports non-preemptive and preemptive CPU scheduling algorithms. • Tasks are always executed on a First-come, First-serve concept. • FCFS is easy to implement and use. • This algorithm is not much efficient in performance, and the wait time is quite high. Advantages of FCFS: • Easy to implement • First come, first serve method Disadvantages of FCFS: • FCFS suffers from Convoy effect. • The average waiting time is much higher than the other algorithms. • FCFS is very simple and easy to implement and hence not much efficient.
  • 9. Process Wait Time : Service Time - Arrival Time P0 0 - 0 = 0 P1 5 - 1 = 4 P2 8 - 2 = 6 P3 16 - 3 = 13 Average Wait Time: (0+4+6+13) / 4 = 5.75
  • 10. Shortest Job First (SJF) Shortest job first (SJF) is a scheduling process that selects the waiting process with the smallest execution time to execute next. This scheduling method may or may not be preemptive. Significantly reduces the average waiting time for other processes waiting to be executed. The full form of SJF is Shortest Job First. Characteristics of SJF: • Shortest Job first has the advantage of having a minimum average waiting time among all operating system scheduling algorithms. • It is associated with each task as a unit of time to complete. • It may cause starvation if shorter processes keep coming. This problem can be solved using the concept of ageing. Advantages of Shortest Job first: • As SJF reduces the average waiting time thus, it is better than the first come first serve scheduling algorithm. • SJF is generally used for long term scheduling Disadvantages of SJF: • One of the demerit SJF has is starvation. • Many times it becomes complicated to predict the length of the upcoming CPU request
  • 11. Process Waiting Time P0 0 - 0 = 0 P1 5 - 1 = 4 P2 14 - 2 = 12 P3 8 - 3 = 5 Average Wait Time: (0 + 4 + 12 + 5)/4 = 21 / 4 = 5.25
  • 12. Longest Job First(LJF) Longest Job First(LJF) scheduling process is just opposite of shortest job first (SJF), as the name suggests this algorithm is based upon the fact that the process with the largest burst time is processed first. Longest Job First is non-preemptive in nature. Characteristics of LJF: • Among all the processes waiting in a waiting queue, CPU is always assigned to the process having largest burst time. • If two processes have the same burst time then the tie is broken using FCFS i.e. the process that arrived first is processed first. • LJF CPU Scheduling can be of both preemptive and non-preemptive types. Advantages of LJF: • No other task can schedule until the longest job or process executes completely. • All the jobs or processes finish at the same time approximately. Disadvantages of LJF: • Generally, the LJF algorithm gives a very high average waiting time and average turn-around time for a given set of processes. • This may lead to convoy effect.
  • 13. Process Arrival Time Burst Time Completion Time Turn around Time = Completion Time – Arrival Time Waiting Time = Turn Around Time – Burst Time P1 1 2 3 3-1=2 2-2=0 P2 2 5 8 8-2=6 6-5=1 P3 3 3 19 19-3=16 16-3=13 P4 4 8 16 16-4=12 12-8=4 Total Turn Around Time = 36 ms So, Average Turn Around Time = 36/4 = 9.00 ms And, Total Waiting Time = 18 ms So, Average Waiting Time = 18/4 = 4.5 ms
  • 14. Highest Response Ratio Next Highest Response Ratio Next is a non-preemptive CPU Scheduling algorithm and it is considered as one of the most optimal scheduling algorithms. The name itself states that we need to find the response ratio of all available processes and select the one with the highest Response Ratio. A process once selected will run till completion. Characteristics of Highest Response Ratio Next: • The criteria for HRRN is Response Ratio, and the mode is Non-Preemptive. • HRRN is considered as the modification of Shortest Job First to reduce the problem of starvation. • In comparison with SJF, during the HRRN scheduling algorithm, the CPU is allotted to the next process which has the highest response ratio and not to the process having less burst time. • Response Ratio = (W + S)/S Here, W is the waiting time of the process so far and S is the Burst time of the process. Advantages of HRRN: • HRRN Scheduling algorithm generally gives better performance than the shortest job first Scheduling. • There is a reduction in waiting time for longer jobs and also it encourages shorter jobs. Disadvantages of HRRN: • The implementation of HRRN scheduling is not possible as it is not possible to know the burst time of every job in advance. • In this scheduling, there may occur an overload on the CPU.
  • 15. Processes Arrival time Burst Time P1 0ms 3ms P2 2ms 6ms P3 4ms 4ms P4 6ms 5ms P5 8ms 2ms Processes Arrival time Burst Time Completion Time Turn Around Time Wait Time P1 0 3 3 3-0 = 3 3-3 = 0 P2 2 6 9 9-2 = 7 7-6 = 1 P3 4 4 13 13-4 = 9 9-4 = 5 P4 6 5 20 20-6 = 14 14-5 = 9 P5 8 2 15 15-8 = 7 7-2 = 5 Total Turn Around Time = 40 ms So, Average Turn Around Time = 40/5 = 8.00 ms And, Total Waiting Time = 20 ms So, Average Waiting Time = 20/5 = 4.00 ms Turn Around Time = Completion Time – Arrival Time Waiting Time = Turn Around Time – Burst Time
  • 16. Priority Scheduling Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method of CPU scheduling algorithm that works based on the priority of a process. In this algorithm, the editor sets the functions to be as important, meaning that the most important process must be done first. In the case of any conflict, that is, where there are more than one processor with equal value, then the most important CPU planning algorithm works on the basis of the FCFS (First Come First Serve) algorithm. Characteristics of Priority Scheduling: • Schedules tasks based on priority. • When the higher priority work arrives while a task with less priority is executed, the higher priority work takes the place of the less priority one. • The latter is suspended until the execution is complete. • Lower is the number assigned, higher is the priority level of a process. Advantages of Priority Scheduling: • The average waiting time is less than FCFS • Less complex Disadvantages of Priority Scheduling:4 • One of the most common demerits of the Preemptive priority CPU scheduling algorithm is the Starvation Problem. This is the problem in which a process has to wait for a longer amount of time to get scheduled into the CPU. This condition is called the starvation problem.
  • 17. Process Waiting Time P0 0 - 0 = 0 P1 11 - 1 = 10 P2 14 - 2 = 12 P3 5 - 3 = 2 Average Wait Time: (0 + 10 + 12 + 2)/4 = 24 / 4 = 6
  • 18. Round Robin  Round Robin is a CPU scheduling algorithm where each process is cyclically assigned a fixed time slot. It is the preemptive version of First come First Serve CPU Scheduling algorithm. Round Robin CPU Algorithm generally focuses on Time Sharing technique.  Characteristics of Round robin  It’s simple, easy to use, and starvation-free as all processes get the balanced CPU allocation.  One of the most widely used methods in CPU scheduling as a core.  It is considered preemptive as the processes are given to the CPU for a very limited time.  Advantages of Round robin  Round robin seems to be fair as every process gets an equal share of CPU.  The newly created process is added to the end of the ready queue.
  • 19. Process Wait Time : Service Time - Arrival Time P0 (0 - 0) + (12 - 3) = 9 P1 (3 - 1) = 2 P2 (6 - 2) + (14 - 9) + (20 - 17) = 12 P3 (9 - 3) + (17 - 12) = 11 Average Wait Time: (9+2+12+11) / 4 = 8.5
  • 20. Shortest Remaining Time First  Shortest remaining time first is the preemptive version of the Shortest job first which we have discussed earlier where the processor is allocated to the job closest to completion. In SRTF the process with the smallest amount of time remaining until completion is selected to execute.  Characteristics of Shortest remaining time first:  SRTF algorithm makes the processing of the jobs faster than SJF algorithm, given it’s overhead charges are not counted.  The context switch is done a lot more times in SRTF than in SJF and consumes the CPU’s valuable time for processing. This adds up to its processing time and diminishes its advantage of fast processing.  Advantages of SRTF:  In SRTF the short processes are handled very fast.  The system also requires very little overhead since it only makes a decision when a process completes or a new process is added.  Disadvantages of SRTF:  Like the shortest job first, it also has the potential for process starvation.  Long processes may be held off indefinitely if short processes are continually added.
  • 21. Process Completion Time Turn Around Time Waiting Time P1 15 15-2 = 13 13-6 = 7 P2 7 7-5 = 2 2-2 = 0 P3 23 23-1 = 22 22-8 = 14 P4 3 3-0 = 3 3-3 = 0 P5 10 10-4 = 6 6-4 = 2 •Average Turn around time = (13 + 2 + 22 + 3 + 6)/5 = 9.2 •Average waiting time = (7 + 0 + 14 + 0 + 2)/5 = 23/5 = 4.6
  • 22. Longest Remaining Time First  The longest remaining time first is a preemptive version of the longest job first scheduling algorithm. This scheduling algorithm is used by the operating system to program incoming processes for use in a systematic way. This algorithm schedules those processes first which have the longest processing time remaining for completion.  Characteristics of longest remaining time first:  Among all the processes waiting in a waiting queue, the CPU is always assigned to the process having the largest burst time.  If two processes have the same burst time then the tie is broken using FCFS i.e. the process that arrived first is processed first.  LJF CPU Scheduling can be of both preemptive and non-preemptive types.  Advantages of LRTF:  No other process can execute until the longest task executes completely.  All the jobs or processes finish at the same time approximately.  Disadvantages of LRTF:  This algorithm gives a very high average waiting time and average turn- around time for a given set of processes.  This may lead to a convoy effect.
  • 23. Processes Arrival Time Burst Time P1 0ms 2ms P2 0ms 3ms P3 2ms 2ms P4 3ms 5ms P5 4ms 4ms Turn Around Time (TAT) = (Completion Time) – (Arrival Time) Also, Waiting Time (WT) = (Turn Around Time) – (Burst Time)