CONCEPT - Shortest Job First (SJF)



Shortest Job First(SJF)

Shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process with the smallest execution time to execute next. SJF is a non-preemptive algorithm. Let us try to understand this with the help of an example.

    Advantages:

  • Minimum average waiting time among all the scheduling algorithms

  • Disadvantages:

  • It may cause starvation if shorter processes keep coming
  • It cannot be implemented at the level of short term CPU scheduling

Example:


Let us take a look at the following image for the example.
There are 4 processes named P1, P2, P3, P4 with burst time 6,8,7,3 respectively.

The completion time of all the processes is 24.
The waiting times of P1, P2, P3, P4 are 3,16,9,0 respectively.
So, the average waiting time is:
(3+16+9+0)/4
= 7