0% found this document useful (0 votes)
21 views

1.5 Different Scheduling Algorithms in Operating System

The document discusses four scheduling algorithms: 1) First Come First Serve (FCFS) selects processes in the order they arrive with no preemption. It has high average waiting times. 2) Shortest Job First (SJF) selects the process with the shortest execution time first, non-preemptively. It improves waiting times but requires estimating process lengths. 3) Shortest Remaining Time Next (SRTN) is a preemptive version of SJF that selects the process with the shortest remaining time, improving waiting times further. It is difficult to estimate remaining times. 4) Round Robin uses time slices to rotate between processes in FCFS order to avoid starvation.

Uploaded by

Darshit Chhatbar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

1.5 Different Scheduling Algorithms in Operating System

The document discusses four scheduling algorithms: 1) First Come First Serve (FCFS) selects processes in the order they arrive with no preemption. It has high average waiting times. 2) Shortest Job First (SJF) selects the process with the shortest execution time first, non-preemptively. It improves waiting times but requires estimating process lengths. 3) Shortest Remaining Time Next (SRTN) is a preemptive version of SJF that selects the process with the shortest remaining time, improving waiting times further. It is difficult to estimate remaining times. 4) Round Robin uses time slices to rotate between processes in FCFS order to avoid starvation.

Uploaded by

Darshit Chhatbar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Q-1 Explain different Scheduling Algorithms.

1) First Come First Serve(FCFS)


➢ Selection Criteria:
• The Process that requests first is served first. It means that processes are served in the exact order
as they come.
➢ Decision Mode:
• Non-Preemptive: Once a process is selected, it runs until it blocks for an I/O or some event, or it
terminates.
➢ Implementation:
• This strategy can be easily implemented by using FIFO queue. FIFO means First In First Out.
• When first process enters the system, it starts its execution.
• All other processes are appended in a queue.
• When 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 following table. Consider all time values in milliseconds. Calculate average
turnaround time and waiting time.
Process Arrival Time(T0) Time required for completion(∆T)
P0 0 10
P1 1 6
P2 3 2
P3 5 4
Gantt Chart:

P0 P1 P2 P3
0 10 16 18 22
• Initially only Process P0 is present and it is allowed to run.
• When P0 completes, all other Processes are present. So next process P1 from ready queue is
selected and allowed to run till it completes.
• This procedure is repeated till all processes complete their execution.
➢ Statistics:
Completion Finish Turnaround
Arrival Time Waiting Time
Process Time Time Time
(T0) (TAT-∆T)
(∆T) (T1) (TAT = T1-T0)
P0 0 10 10 10 0
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.25 ms


➢ Average Waiting Time: (0+9+13+13)/4 = 35/4 = 8.75 ms

➢ Advantages:
o Simple ,No Starvation
o Easy to understand, easy to implement.
➢ Disadvantages:
o Not efficient. Average waiting time is too high.
o All small processes wait for one big process to acquire CPU.
o CPU utilization may be too low.

2) Shortest Job First (SJF) Scheduling Algorithm.


➢ Selection Criteria:
• The Process that requires shortest time to complete the execution, is served first.
➢ Decision Mode:

• Non-Preemptive: once a process is selected, it runs until it blocks for an I/O or some event, or it
terminates.

➢ Implementation:
• This strategy can be easily implemented by using FIFO queue. FIFO means First In First Out.
• All processes in a queue are sorted in ascending order based on their required CPU bursts.
• When 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 following table. Consider all time values in milliseconds.
Process Arrival Time(T0) Time required for completion(∆T)
P0 0 10
P1 1 6
P2 3 2
P3 5 4

➢ Gantt Chart:

P0 P2 P3 P1
0 10 12 16 22

• Initially only Process P0 is present and it is allowed to run.


• But, when P0 completes, all other Processes are present. So process with shortest CPU Burst P2 is
selected and allowed to run till it completes.
• When P2 completes execution, next process selected whose burst time is smaller. In our case its
P3.
• Whenever more than one process is available, such type of decision is taken.
• This procedure is repeated till all processes complete their execution.
➢ Statistics:
Turnaround Waiting
Arrival Time Completion Time Finish Time
Process Time Time
(T0) (∆T) (T1)
(TAT = T1-T0) (TAT-∆T)
P0 0 10 10 10 0
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.75 ms


➢ Average Waiting Time: (0+15+7+7)/4 = 29/4 = 7.25 ms
➢ Advantages:
o Less Waiting time
o Good Response for shortest processes.
➢ Disadvantages:
o It is difficult to estimate time required to complete execution.
o Starvation is possible for long process. Long process may wait forever.

3) Shortest Remaining Time Next(SRTN) Scheduling Algorithm


➢ Selection Criteria:
• The Process, whose remaining time is shortest, is served first. This is a preemptive version of SJF
scheduling.
➢ Decision Mode:
• Preemptive: when a new process arrives, its total time is compared to the current process’s
remaining time.
• If the new job needs less time to finish than the current process, the current process is suspended
and the new process started.
➢ Implementation:
• This strategy can be easily implemented by using FIFO queue. FIFO means First in First Out.
• All processes in a queue are sorted in ascending order based on their remaining run time. When
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 following table. Consider all time values in milliseconds.
Process Arrival Time(T0) Time required for completion(∆T)
P0 0 10
P1 1 6
P2 3 2
P3 5 4

➢ Gantt Chart:

P0 P1 P2 P1 P3 P0
0 1 3 5 9 13 22
• Initially only Process P0 is present and it is allowed to run.
• But, when P1 comes, its total time is smaller than P0’s remaining run time.
• So, P0 is preempted and P1 is allowed to run.
• Whenever new process comes or current process blocks, such type of decision is taken. This
procedure is repeated till all processes complete their execution.
➢ Statistics:
Arrival Completion Finish Turnaround
Waiting Time
Process Time Time Time Time
(TAT-∆T)
(T0) (∆T) (T1) (TAT = T1-T0)
P0 0 10 22 22 12
P1 1 6 9 8 2
P2 3 2 5 2 0
P3 5 4 13 8 4

➢ Average Turn-Around Time: (22+9+5+13)/4 = 40/4 = 10.00 ms


➢ Average Waiting Time: (12+2+0+4)/4 = 18/4 = 4.5 ms

➢ Advantages:
o Less Waiting time
o Good Response for shortest processes.

➢ Disadvantages:
o It is difficult to estimate remaining time necessary to complete execution.
o Starvation is possible for long process. Long process may wait forever.
4) Round Robin Scheduling Algorithm
➢ Selection Criteria:
• The process that requests first is served first. It means that processes are served in the exact order
as they come. The selection criteria are same as that of FCFS scheduling.
➢ Decision Mode:
• Preemptive: Each selected process is assigned a time interval, called time quantum or time slice.
Process is allowed to run only for this time interval.
• Here, one of two things is possible: first, process needs CPU burst less than time quantum. In this
case, process will voluntarily release CPU and it will be moved to the end of the queue.
• Second, process needs CPU burst longer than quantum. In this case, process will be running at the
end of time quantum. Then, it will be preempted and moved to the end of the queue. CPU will be
allocated to another process.

➢ Implementation:
• This strategy can be easily implemented by using FIFO queue. FIFO means First in First Out.
• When new process comes, or process releases CPU, or process is preempted, it is moved to the end
of the queue. When 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 following table. Consider all time values in milliseconds. Consider time
quantum is of 4ms and context switch overhead is of 1ms
Process Arrival Time(T0) Time required for completion(∆T)
P0 0 10
P1 1 6
P2 3 2
P3 5 4

➢ Gantt Chart:

P0 P1 P2 P0 P3 P1 P0
0 4 5 9 10 12 13 17 18 22 23 25 26 28
• Initially only Process P0 is present and it is allowed to run.
• Here time slice is of 4ms. So P1 is allow to run for 4ms only.
• When P0 timing is over then P0 is preempted and P1 is allowed to run. P1 is allow to run for fix
time duration (here 4ms). After its time slice completes it executes next process.

• Whenever new process comes or current process blocks, such type of decision is taken. This
procedure is repeated till all processes complete their execution.
➢ Statistics:
Arrival Completion Finish Waiting
Turnaround Time
Process Time Time Time Time
(TAT = T1-T0)
(T0) (∆T) (T1) (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 = 78/4 = 19.5ms


➢ Average Waiting Time: (18+18+7+13)/4 = 56/4 = 14.0ms

➢ Advantages:
o Oldest, simplest and most widely used algorithms.
➢ Disadvantages:
o Context switch overhead is there.
o Determination of time quantum is too critical. If it is too short, it cause frequent context
switches. If it is too long, it cause poor response for short interactive processes.

You might also like