What is SJF Scheduling
Shortest Job First (SJF) Scheduling
SJF is a full form of (Shortest job first) is a scheduling algorithm in which the process with the shortest execution time should be selected for execution next. This scheduling method can be preemptive or non-preemptive. It significantly reduces the average waiting time for other processes awaiting execution.
The job with the shortest burst time will get the CPU first. The lesser the burst time, the sooner will the process get the CPU. It is the non-preemptive type of scheduling.
Advantage of SJF Method
- It is associated with each job as a unit of time to complete.
- In this method, when the CPU is available, the next process or job with the shortest completion time will be executed first.
- It is Implemented with non-preemptive policy.
- This algorithm method is useful for batch-type processing, where waiting for jobs to complete is not critical.
- It improves job output by offering shorter jobs, which should be executed first, which mostly have a shorter turnaround time.
Disadvantages of SJF Method
- 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.
Example of SJF Scheduling
In the following example, there are five jobs named as P1, P2, P3, P4 and P5. Their arrival time and burst time are given in the table below.
|Process ID||Arrival Time||Burst Time||Completion Time||Turn Around Time||Waiting Time|
Since, No Process arrives at time 0 hence; there will be an empty slot in the Gantt chart from time 0 to 1 (the time at which the first process arrives).
According to the algorithm, the OS schedules the process which is having the lowest burst time among the available processes in the ready queue.
Till now, we have only one process in the ready queue hence the scheduler will schedule this to the processor no matter what is its burst time.
This will be executed till 8 units of time. Till then we have three more processes arrived in the ready queue hence the scheduler will choose the process with the lowest burst time.
Among the processes given in the table, P3 will be executed next since it is having the lowest burst time among all the available processes.
So that's how the procedure will go on in shortest job first (SJF) scheduling algorithm.
Avg Waiting Time = 27/5