1.5 Different Scheduling Algorithms in Operating System
1.5 Different Scheduling Algorithms in Operating System
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
➢ 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.
• 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
➢ 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
➢ 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
➢ 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.