What is Shortest Job First Scheduling?
Shortest Job First (SJF) is an algorithm in which the process having the smallest execution time is chosen for the next execution. This scheduling method can be preemptive or non-preemptive. It significantly reduces the average waiting time for other processes awaiting execution.
Characteristics of SJF Scheduling
- It is associated with each job as a unit of time to complete.
- This algorithm method is helpful for batch-type processing, where waiting for jobs to complete is not critical.
- It can improve process throughput by making sure that shorter jobs are executed first, hence possibly have a short turnaround time.
- It improves job output by offering shorter jobs, which should be executed first, which mostly have a shorter turnaround time.
There are Two Types of SJF Methods
Non-Preemptive SJF (Shortest Remaining Time First)
In non-preemptive scheduling, once the CPU cycle is allocated to process, the process holds it till it reaches a waiting state or terminated.
Preemptive SJF
In Preemptive SJF Scheduling, jobs are put into the ready queue as they come. A process with shortest burst time begins execution. If a process with even a shorter burst time arrives, the current process is removed or preempted from execution, and the shorter job is allocated CPU cycle.
Advantages
- Maximum throughput
- Minimum average waiting and turnaround time
Disadvantages
- May suffer with the problem of starvation.
- It is not implementable because the exact Burst time for a process can't be known in advance.
Algorithm
- Sort all the processes according to their arrival time.
- Select the process with minimum arrival time as well as minimum burst time.
- After completion of the process, select from the ready queue the process which has the minimum burst time.
- Repeat above processes untill all processes have finished their execution.