0% found this document useful (0 votes)
25 views77 pages

CPU Scheduling

The document discusses process states and CPU scheduling. It defines key terms like process, process state diagram, and scheduling objectives. It then explains in detail two CPU scheduling algorithms: 1) First Come First Serve (FCFS) scheduling is the simplest algorithm that executes processes in the order of their arrival. 2) Shortest Job First (SJF) scheduling selects the waiting process with the smallest burst time/duration to execute next, reducing average waiting times. The document provides examples and comparisons of these two non-preemptive scheduling algorithms.

Uploaded by

dattasai sreya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views77 pages

CPU Scheduling

The document discusses process states and CPU scheduling. It defines key terms like process, process state diagram, and scheduling objectives. It then explains in detail two CPU scheduling algorithms: 1) First Come First Serve (FCFS) scheduling is the simplest algorithm that executes processes in the order of their arrival. 2) Shortest Job First (SJF) scheduling selects the waiting process with the smallest burst time/duration to execute next, reducing average waiting times. The document provides examples and comparisons of these two non-preemptive scheduling algorithms.

Uploaded by

dattasai sreya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Avant-Garde Operating Systems

M.Tech (CSE) : I Year I Semester


2023-2024, Odd Sem.

CPU SCHEDULING
Course Code L T P S Credits
23CS5103 3 0 2 0 4
Process and its State
Process:-

➢A Program does nothing unless its instructions are executed by a CPU. A


program in execution is called a process.

➢In order to accomplish its task, process needs the computer resources.

➢There may exist more than one process in the system which may require
the same resource at the same time. Therefore, the operating system has
to manage all the processes and the resources in a convenient and efficient
way.
Process and its State
Process States:-

➢The process, from its creation to completion, passes through various


states.

➢The minimum number of states is five.


Process and its State
Process State Diagram:-
Process and its State
1. New:- A program which is going to be picked up by the OS into the main
memory is called a new process.

2. Ready:- Whenever a process is created, it directly enters in the ready


state, in which, it waits for the CPU to be assigned. The OS picks the new
processes from the secondary memory and put all of them in the main
memory. The processes which are ready for the execution and reside in
the main memory are called ready state processes. There can be many
processes present in the ready state.
Process and its State
3. Running
✓One of the processes from the ready state will be chosen by the OS
depending upon the scheduling algorithm.
✓Hence, if we have only one CPU in our system, the number of running
processes for a particular time will always be one.
✓If we have n processors in the system then we can have n processes
running simultaneously.
Process and its State
4. Block or wait

✓From the Running state, a process can make the transition to the block or
wait state depending upon the scheduling algorithm or the intrinsic
behavior of the process.

✓When a process waits for a certain resource to be assigned or for the input
from the user then the OS move this process to the block or wait state and
assigns the CPU to the other processes.
Process and its State
5. Completion or termination
✓When a process finishes its execution, it comes in the termination state.
✓All the context of the process (Process Control Block) will also be
deleted the process will be terminated by the Operating system.
Operations of the process
1. Creation:- Once the process is created, it will be ready and come into the ready queue (main
memory) and will be ready for the execution.

2. Scheduling:- Out of the many processes present in the ready queue, the Operating system
chooses one process and start executing it. Selecting the process which is to be executed next, is
known as scheduling.

3. Execution:- Once the process is scheduled for the execution, the processor starts executing it.
Process may come to the blocked or wait state during the execution then in that case the
processor starts executing the other processes.

4. Deletion/killing:- Once the purpose of the process gets over then the OS will kill the process.
The Context of the process (PCB) will be deleted and the process gets terminated by the
Operating system.
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.
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.
Terminologies of 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. (Duration)

➢Turn Around Time: Time Difference between completion time and arrival
time. Turn Around Time = Completion Time – Arrival Time

➢ Waiting Time(W.T): Time Difference between turn around time and burst
time. Waiting Time = Turn Around Time – Burst Time
Example to understand the term
➢Arrival Time: 11 am (entered in the bank to deposit cash).

➢Completion Time: 12PM

➢Burst Time: 15 minutes(time for cash deposit-useful time or ideal time)

➢Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time = Completion Time – Arrival Time (12 pm-11am) or we can
say 60 minute.

➢ Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time (60 minute-15 minute=45 minute)
➢Response Time: (The time at which a process gets CPU first time-Arrival Time)
Types of CPU Scheduling Algorithm

➢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.
Types of CPU Scheduling Algorithm

Non Pre-Emptive Pre-Emptive


FCFS(First Come First Serve) PRIORITY BASED
SJF(Shortest Job First) ROUND ROBIN
LJF(Longest Job First) SRTF(Shortest Remaining Time first)
HRRN(Highest Response Ratio Next) LRTF(Longest Remaining Time first)
1. First Come First Serve:

➢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.
1. First Come First Serve:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Arrival Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 0 2
2 P2 1 2
3 P3 5 3
4 P4 6 4
1. First Come First Serve:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Arrival Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 0 2 2
2 P2 1 2 4
3 P3 5 3 8
4 P4 6 4 12
1. First Come First Serve:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Arrival Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 0 2 2 2 (2-0)
2 P2 1 2 4 3 (4-1)
3 P3 5 3 8 3 (8-5)
4 P4 6 4 12 6 (12-6)
Average TAT=2+3+3+6=14/4=3.5
1. First Come First Serve:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Arrival Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 0 2 2 2 (2-0) 0 (2-2) 0 (0-0)
2 P2 1 2 4 3 (4-1) 1 (3-2) 1 (2-1)
3 P3 5 3 8 3 (8-5) 0 (3-3) 0 (5-5)
4 P4 6 4 12 6 (12-6) 2 (6-4) 2 (8-6)
Average TAT=2+3+3+6=14/4=3.5
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.
2. 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.
2. Shortest Job First (SJF):
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Burst Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 1 3
2 P2 2 4
3 P3 1 2
4 P4 4 4
2. Shortest Job First (SJF):
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Burst Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 1 3
2 P2 2 4
3 P3 1 2
4 P4 4 4
2. Shortest Job First (SJF):
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Burst Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 1 3 6
2 P2 2 4 10
3 P3 1 2 3
4 P4 4 4 14
2. Shortest Job First (SJF):
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Burst Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 1 3 6 5
2 P2 2 4 10 8
3 P3 1 2 3 2
4 P4 4 4 14 10
Average TAT=5+8+2+10=25/4=6.25
2. Shortest Job First (SJF):
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Burst Time
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Non Pre-Emptive
1 P1 1 3 6 5 2 2
2 P2 2 4 10 8 4 4
3 P3 1 2 3 2 0 0
4 P4 4 4 14 10 6 6
Average TAT=5+8+2+10=25/4=6.25
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.
30
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

31
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.

32
3. 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 most important process must be done


first.

33
3. Priority Scheduling:

• 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.

34
3. Priority Scheduling:
Example:
Priority Process Arrival Burst Completion TAT WT RT Criteria - Priority
no No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
10 P1 0 5 Priority:-Higher the
number, higher the priority
20 P2 1 4
30 P3 2 2
40 P4 4 1
3. Priority Scheduling:
Example:
Priority Process Arrival Burst Completion TAT WT RT Criteria - Priority
no No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
10 P1 0 5 12 Priority:-Higher the
number, higher the priority
20 P2 1 4 8
30 P3 2 2 4
40 P4 4 1 5
3. Priority Scheduling:
Example:
Priority Process Arrival Burst Completion TAT WT RT Criteria - Priority
no No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
10 P1 0 5 12 12 7 (12-5) Priority:-Higher the
number, higher the priority
20 P2 1 4 8 7 3 (7-4)
30 P3 2 2 4 2 0 (2-2)
40 P4 4 1 5 1 0 (1-1)
3. Priority Scheduling:
Example:
Priority Process Arrival Burst Completion TAT WT RT Criteria - Priority
no No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
10 P1 0 5 12 12 7 (12-5) Priority:-Higher the
number, higher the priority
20 P2 1 4 8 7 3 (7-4)
30 P3 2 2 4 2 0 (2-2)
40 P4 4 1 5 1 0 (1-1)
Average TAT=22/4=5.5
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 and the latter is suspended until the
execution is complete.

• Lower is the number assigned, higher is the priority level of a


process.
39
Advantages of Priority Scheduling:

• The average waiting time is less than FCFS

• Less complex

40
Disadvantages of Priority Scheduling:

• 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.

41
4. 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.

42
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 Given Time Quantum - 2
2 P2 1 4
3 P3 2 2
4 P4 4 1

Ready Queue
Running
(RAM)
Ready
Running Queue
(CPU)
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 Given Time Quantum - 2
2 P2 1 4
3 P3 2 2
4 P4 4 1

Ready Queue P1
Running
(RAM) 0
Ready
Running Queue
(CPU) P1
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 Given Time Quantum - 2
2 P2 1 4
3 P3 2 2
4 P4 4 1

Ready Queue P1
Running
(RAM) 0
Ready
Running Queue
P1
(CPU) P1
0 2
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 Given Time Quantum - 2
2 P2 1 4
3 P3 2 2
4 P4 4 1

Ready Queue P1
Running
(RAM) 0
Ready
Running Queue
P1
(CPU) P1
0 2
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 Given Time Quantum - 2
2 P2 1 4
3 P3 2 2
4 P4 4 1

Ready Queue P1 P2 P3
Running
0
Ready
Running Queue
P1
0 2 P1
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2
4 P4 4 1

P1

Ready Queue P1 P2 P3 P1
Running
0
Ready
Running Queue
P1 P2
0 2 4 P1
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2
4 P4 4 1

Ready Queue P1 P2 P3 P1 P4 Running


0
Ready
Running Queue
P1 P2
0 2 4
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2
4 P4 4 1

Ready Queue P1 P2 P3 P1 P4 P2
Running
0
Ready
Running Queue
P1 P2
0 2 4
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2 0
4 P4 4 1

Ready Queue P1 P2 P3 P1 P4 P2
Running
0
Ready
Running Queue
P1 P2 P3
0 2 4 6
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 1 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2 0
4 P4 4 1

Ready Queue P1 P2 P3 P1 P4 P2
Running
0
Ready
Running Queue 2
P1 P2 P3 P1
0 2 4 6 8 P1
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 1 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2 0
4 P4 4 1

Ready Queue P1 P2 P3 P1 P4 P2 P1
Running
0
Ready
Running Queue
P1 P2 P3 P1
0 2 4 6 8
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 1 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2 0
4 P4 4 1 0

Ready Queue P1 P2 P3 P1 P4 P2 P1
Running
0
Ready
Running Queue
P1 P2 P3 P1 P4
0 2 4 6 8 9
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 1 Given Time Quantum - 2
2 P2 1 4 2
3 P3 2 2 0
4 P4 4 1 0

Ready Queue P1 P2 P3 P1 P4 P2 P1
Running
0
Ready
Running Queue
P1 P2 P3 P1 P4
0 2 4 6 8 9
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 1 Given Time Quantum - 2
2 P2 1 4 2 0
3 P3 2 2 0
4 P4 4 1 0

Ready Queue P1 P2 P3 P1 P4 P2 P1
Running
0
Ready
Running Queue
P1 P2 P3 P1 P4 P2
0 2 4 6 8 9 11
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 1 Given Time Quantum - 2
2 P2 1 4 2 0
3 P3 2 2 0
4 P4 4 1 0

Ready Queue P1 P2 P3 P1 P4 P2 P1
Running
0
Ready
Running Queue
P1 P2 P3 P1 P4 P2 P1
0 2 4 6 8 9 11 12
4. Round robin:
Example:
S.no Process Arrival Burst Completion TAT WT RT Criteria - Time Quantum
No Time(AT) Time Time (CT) (CT-AT) (TAT-BT) Mode- Pre-Emptive
1 P1 0 5 3 1 12 12 7 0 (0-0) Given Time Quantum - 2
2 P2 1 4 2 11 10 6 1 (2-1)
3 P3 2 2 0 6 4 2 2 (4-2)
4 P4 4 1 0 9 5 4 4 (8-4)

Ready Queue P1 P2 P3 P1 P4 P2 P1
Running
0
Ready
Running Queue
P1 P2 P3 P1 P4 P2 P1
0 2 4 6 8 9 11 12
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.
59
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.

60
5. 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.

61
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.

62
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.

63
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.

64
6. 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.

65
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.

66
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.

67
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.

68
7. 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.

69
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.

70
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.

71
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.

72
8. 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.

73
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.

74
Characteristics of Highest Response Ratio Next:

• 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.

75
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.

76
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.

77

You might also like