![]() |
VOOZH | about |
Shortest Job First (SJF) or Shortest Job Next (SJN) is a scheduling process that selects the waiting process with the smallest execution time to execute next. This scheduling method may or may not be preemptive. Significantly reduces the average waiting time for other processes waiting to be executed.
The Shortest Job First (SJF) Scheduling algorithm selects the process with the smallest burst time for execution. But in some cases, the exact burst time of a process may not be known in advance. In such scenarios, an estimation formula is used to predict the next burst time based on the previous burst times.
Estimation Formula
Where:
Example: Consider the following table of arrival time and burst time for three processes P1, P2 and P3.
| Process | Burst Time | Arrival Time |
|---|---|---|
| P1 | 6 ms | 0 ms |
| P2 | 8 ms | 2 ms |
| P3 | 3 ms | 4 ms |
Step-by-Step Execution:
Gantt chart :
As we know,
- Turn Around time = Completion time - arrival time
- Waiting Time = Turn around time - burst time
Now, lets calculate average waiting time and turn around time:
| Process | Arrival Time (AT) | Burst Time (BT) | Completion Time (CT) | Turn Around Time (TAT) | Waiting Time (WT) |
|---|---|---|---|---|---|
| P1 | 0 | 6 | 6 | 6-0 = 6 | 6-6 = 0 |
| P2 | 2 | 8 | 17 | 17-2 = 15 | 15-8 = 7 |
| P3 | 4 | 3 | 9 | 9-4 = 5 | 5-3 = 2 |
- Average Turn around time = (6 + 15 + 5)/3 = 8.6 ms
- Average waiting time = ( 2 + 0 + 7 )/3 = 9/3 = 3 ms
To learn about Preemptive Shortest Job First or Shortest Remaining Time First, please refer the following
To learn about Non-Preemptive Shortest Job First, please refer the following
Step 1: Input number of processes and their burst times (arrival time too, if itβs non-preemptive with arrivals).
Step 2: Sort processes by burst time (if same, use arrival order).
Step 3: Start with the process having the shortest burst time.
Step 4: Calculate Completion Time = Start Time + Burst Time.
Step 5: Calculate Turnaround Time = Completion Time β Arrival Time.
Step 6: Calculate Waiting Time = Turnaround Time β Burst Time.
Step 7: Repeat until all processes are completed.
Step 8: Compute average waiting time and turnaround time.
Step 9: Display completion, waiting, and turnaround times for each process along with averages.
To learn about how to implement this CPU scheduling algorithm, please refer the following