You are on page 1of 19

SCHEDULING ALGORITHM

INDEX
SR.NO. TOPIC NAME

1 What is Scheduling Algorithm ?

2. Types of Scheduling Algorithm

3. Goals of Scheduling Algorithm

4. FCFS (First Come First Served)

5. SJF (Shortest Job First)

6. RR (Round Robin)
WHAT IS SCHEDULING
ALGORITHM ?

▪ Scheduling Algorithm is an algorithm which is used by Scheduler in


making choices of which process to run next whenever more than one
processes are simultaneously in the ‘Ready’ state.
▪ The Scheduling Algorithm is known as ‘Scheduling policy’.
▪ There are various scheduling algorithm available. All these work based
on different criteria to make a choice
▪ Scheduling Algorithm can be either non-preemptive and preemptive
Types Of Scheduling Algorithm

01 First Come, First Served(FCFS)

02 Shortest Job First (SJF)

03 Shortest Remaining Time Next(SRTN)

04 Round Robin Scheduling(RR)

05 Priority Based Non -Preemptive Scheduling

06 Priority Based Preemptive Scheduling

07 Multilevel Queue Scheduling(MLQ )


GOALS
2.

The algorithm should ensure that all


processes are treated fairly, and that no
1. process is starved of CPU time. 3.

The algorithm should The algorithm should


try to keep the CPU as have minimal
busy as possible. overhead, so that it
does not consume too
much of CPU’s time.
First come First Served

Selection Criteria • The process that requests first is served first.


• It means that processes are served in exact order they come.

Non Preemptive: Once a process is selected. It runs until it blocks for Decision Mode
an I\O or some event or terminates.

• This strategy can be easily implemented by using FIFO queue. FIFO


Implementation means First in First out.
• When the first process enters the system is starts execution. All other
processes are appended in queue.
• When the CPU becomes free , a process from the first position in a
queue is selected to run.
Example: Consider the following set of four processes. Their arrival time and time required to
complete the execution are given in the following table. Consider all time values in
milliseconds.
Process Arrival Time(T0) Time required for completion(?t)
P0 0 10

P1 1 Objective n° 2 6

P2 . 3 2 .

P3 5 4

➢ Gantt Chart:

P0 P1 P2 P3

0 10 16 18 22
• Initially, only one process P0 is present, and it is allowed to run.
• But, when P0 completes, all other processes are present. So, the next process (P1) from a ready queue is selected and
allowed to run till it completes.
• This procedure is repeated till all processes complete their execution.
➢ Statistics :

Time required for Turn around time Waiting Time


Process Arrival Time(T0) Finish Time
completion(?t) (TAT=T1-T0) (TAT-?T)

P0 0 10 10 10 0

Objective n° 2
P1 1 6 16 15 9

P2 . 3 2 18 15 . 13

P3 5 4 22 17 13

➢ Average Turn-around time: (10+15+15+17)/4 = 57/4 =14.25ms


➢ Average Waiting Time(0+9+13+13)= 35/4=8.75ms
➢ Advantages
▪ Simple Fair, No Starvation
▪ Easy to understand
▪ Easy to implement

➢ Disadvantages
▪ Not efficient: The average waiting time is too high.
L
▪ A Convoy effect is possible. All small process es wait for one big process to acquire CPU. What if some 1 minute process is
behind 10 minute process
▪ CPU utilization may be too low. Consider a CPU-Bound process running with many I/O- bound processes
Shortest Job First(SJF)

Selection Criteria • The process that requires the shortest time to complete execution is
served first.

• Non Preemptive: Once a process is selected. It runs until it blocks Decision Mode
for an I\O or some event or terminates.

• This strategy can be easily implemented by using a sorted FIFO queue.


Implementation FIFO means First in First out.
• All the processes in a queue are sorted in ascending order based on their
required CPU bursts.
• When the CPU becomes free , a process from the first position in a
queue is selected to run
Example: Consider the following set of four processes. Their arrival time and time required to
complete the execution are given in the following table. Consider all time values in
milliseconds.
Process Arrival Time(T0) Time required for completion(?t)
P0 0 10

P1 1 Objective n° 2 6

P2 . 3 2 .

P3 5 4

➢ Gantt Chart:

P0 P2 P3 P1

0 10 12 16 22
• Initially, only one process P0 is present, and it is allowed to run.
• But, when P0 completes, all other processes are present. So, the next process with the shortest CPU burst (P2) is selected
and allowed to run till it completes.
• This type of decision is taken whenever more than one process is available.
• This procedure is repeated till all the processes complete their execution.
➢ Statistics :

Time required for Turn around time Waiting Time


Process Arrival Time(T0) Finish Time
completion(?t) (TAT=T1-T0) (TAT-?T)

P0 0 10 10 10 0

Objective n° 2
P1 1 6 22 21 15

P2 . 3 2 12 9 . 7

P3 5 4 16 11 7

➢ Average Turn-around time: (10+21+9+11)/4 = 51/4 =12.75ms


➢ Average Waiting Time(0+15+7+7)= 29/4=7.25ms
➢ Advantages
▪ Less waiting time.
▪ Good response for short processes.

➢ Disadvantages
▪ It is difficult to estimate the time required to complete their execution.
▪ Starvation is possible for a long process. The long process may wait forever.
L
Round Robin Scheduling(RR)

Selection Criteria • The process that requests first is served first.


• It means that processes are served in exact order they come.
• The selection criteria are the same as that as of FCFS scheduling.

• Preemptive: Each selected process is assigned a time interval, called


time quantum or time slice. The process is allowed to run for this time
interval.
• Here, one of two things is possible: Decision
1. First, a process needs CPU burst less than time quantum. In this case Mode
the process voluntarily releases the CPU and is moved to the end of
queue
2. Second, a process needs CPU burst longer than time quantum. In this
case the process will be running at the end of time quantum. Now , it
will be preempted and moved to the end of queue. CPU will be
allocated to another process
• Here, the length of time quantum is critical to determine.
Round Robin Scheduling(RR)

• This strategy can be implemented can be implemented by using


Implementation circular FIFO queue.
• When the new process comes, or the process releases CPU, or the
process is preempted, it is moved to the end of the queue.
• When the CPU becomes free, a process from the first position in a
queue is selected to run.
Example: Consider the following set of four processes. Their arrival time and time required to
complete the execution are given in the following table. Consider all time values in
milliseconds.
Process Arrival Time(T0) Time required for completion(?t)
P0 0 10

P1 1 Objective n° 2 6

P2 . 3 2 .

P3 5 4

➢ Gantt Chart:

P0 P1 P2 P0 P3 P1 P0

0 4 8 10 14 18 20 22
➢ Ready Queue :

P1 P2 P0 P3 P1 P0
• At 4ms, process completes its time quantum.
• So it is preempted, and another process P1 is allowed to run.
• At 12ms,process P2 voluntarily releases the CPU, and another process P0 is selected to run.
• 1ms is wasted on each context switch overhead.
• This procedure is repeated till all processes complete their execution.

Objective n° 2
➢ Statistics :
. .
Arrival Time required for Turn around time Waiting Time
Process Finish Time
Time(T0) completion(?t) (TAT=T1-T0) (TAT-?T)

P0
0 10 28 28 18

P1 1 6 25 24 18

P2 3 2 12 9 7

P3 5 4 22 17 13

➢ Average Turn-around time: (28+24+9+17)/4 = 51/4 =19.5ms


➢ Average Waiting Time(18+18+7+13)= 56/4=14.0ms
➢ Advantages
▪ One of the oldest, simplest, fairest and most widely used algorithms.

➢ Disadvantages
▪ Context switch is overheaded.
▪ The determination of time quantum is too critical. If it is too short, it causes frequent context switches and lowers CPU
L
efficiency. If it is too long, it causes poor response for short interactive processes.
THANK
YOU

You might also like