Shortest Job First
SJF stands for Shortest Job First. In this method, out of all available process CPU is assigned to the process having the shortest burst time requirements. It means that it does not depend on the priority or seniority of the processes. If two processes have the same time burst time, the CPU uses First Come First Serve (FCFS) is used to break the tie. As a result, it helps to reduce average waiting time of processes. Therefore, shorter processes finish their execution quickly, while longer processes may have to wait for a long time. This problem is called the starvation. However, SJF has both pre-emptive and non pre-emptive scheduling.
In SJF scheduling, the CPU is assigned to the process having the shortest burst time to reduce the average waiting time.
Types of SJF Scheduling
There are two types of SJF Scheduling are as given below.
i) Pre-Emptive SJF
ii) Non Pre-Emptive SJF
1. Pre-Emptive SJF
Pre-Emptive SJF is the type of Shortest Job First. The CPU can be taken from the running process if a new process arrives with a shorter remaining burst time. Therefore, this method is also known as Shortest Remaining Job First (SRJF).
2. Non Pre-Emptive SJF
Non Pre-Emptive SJF is also the type of Shortest Job First. In this method, once a process gets the CPU, it continues execution until it finishes its CPU burst or blocks.
Example of SJF Scheduling
Suppose there are four processes P0, P1, P2 and P3, having different burst time.

Explanation
In table show the different kinds of CPU Scheduling Parameters. Therefore, first one is Process id, second is Arrival Time, and up so on in the last is Waiting Time (WT). So, a few CPU Scheduling Parameters explanation as given below.
Completion Time (CT)
CT stand for Completion Time. It means that to calculate Completion Time (CT), add Arrival Time (AT) and Turnaround Time (TAT).
- Formula
CT = Arrival Time (AT) + Turnaround Time (TAT)
- Example: P0
Arrival Time = 0
Turnaround Time = 6
- CT = 0+6 = 6
Turnaround Time (TAT)
When process enter the ready queue and complete than time of completion and ready queue is known as TAT.
- Formula
TAT = Completion Time – Arrival Time
- Example: P0
Arrival Time = 0
Completion Time = 6
- TAT = 6-0 = 6
Waiting Time (WT)
In waiting time subtracting burst time from turnaround time is called waiting time.
- Formula
WT = Turnaround Time – Burst Time
- Example: P0
Turnaround Time = 6
Burst Time = 6
- WT = 6-6 = 0
| Note: P0 does not wait to get the CPU. |
Average Turnaround Time (ATAT)
Average Turnaround Time (ATAT) is the average time taken by all processes to complete their execution.
- Formula
Average TAT = Sum of Turnaround Times / Total No of Processes
Sum of Turnaround Times = 6 + 19 + 6 + 5
Total No of Processes = 4
= (6 + 19 + 6 + 5 ) / 4
ATAT = 36 / 4
- ATAT = 9 time units
Average Waiting Time (AWT)
Average Waiting Time (AWT) is the average time that all processes spend waiting in the ready queue.
- Formula
Average WT = Sum of Waiting Times / Total No of Processes
Sum of Waiting Times = 0 + 9 + 2 + 2
Total No of Processes = 4
= (0 + 9 + 2 + 2 ) / 4
AWT = 13 / 4
- AWT = 3.25 time units
Gantt Chart
A Gantt chart is a diagram that shows the order and execution time of processes on the CPU.
Gantt Chart Explanation
- P0: Executes from 0 to 6.
- P2: Executes from 6 to 10.
- P3: Executes from 10 to 13.
- P1: Executes from 13 to 23.
Execution Order: P0 → P2→ P3 → P1
Advantages of SJF
- It reduce average waiting time and turnaround time
- In SJF, maximum throughput it means that more processes may finish less time.
- Short processes may finish quickly.
Disadvantages of SJF
- Long processes may wait for long time.
- It is difficult to predict the exact burst time.
- Short processes get priority over long processes.
| Note: SJF can improve the throughput, but it does not always guarantee maximum throughput. |