SJF Full Form
SJF stands for Shortest Job First. It is a type of CPU scheduling. This algorithm associate with each process the length of the latter’s next CPU burst. When the CPU is available, it is assigned to the process that has the smallest next CPU burst time. It is a scheduling policy that selects for executing the waiting process with the smallest execution time. If two processes have the same length next CPU burst, First Come will be executed.
- The SJF algorithm may be either preemptive or non-preemptive.
- Shortest remaining time Scheduling is a preemptive variant of SJF scheduling.
- This algorithm method is helpful for batch-type processing.
- SJF scheduling is used frequently in long-term scheduling.
Here, we are given 4 processes P1, P2, P3, and P4 and their burst time is 6, 8, 7, 3 respectively.
Let us assume they all arrive at the same time.
By definition of SJF scheduling, we can say that P4 will execute first, then P1, then P3, and at last P2 will execute.
Gantt chart will be:-
The waiting time is 3 unit time for process P1, 16 unit time for process P2, 9 unit time for process P3, and 0 unit time for process P4.
Hence average waiting time is (3 + 16 + 9 + 0)/4 = 7 unit time.
- It reduces the average waiting time.
- SJF scheduling gives the lowest average waiting time for a specific set of processes.
- Probably optimal with regard to average turnaround time.
- It cannot be implemented at the level of short-term CPU scheduling.
- It can leads to starvation of other processes if burst time of running process is very large.
- Total execution time of a job must be known before execution.
- There is no way to know the length of the next CPU burst.