![]() |
VOOZH | about |
The pre-emptive version of Shortest Job First (SJF) scheduling is called Shortest Remaining Time First (SRTF). In SRTF, the process with the least time left to finish is selected to run. The running process continues until it finishes or a new process with a shorter remaining time arrives, ensuring the fastest finishing process always gets priority.
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 | 0 ms |
| P3 | 5 ms | 0 ms |
Step-by-Step Execution:
Gantt chart :
Now, lets calculate average waiting time and turn around time:
As we know,
- Turn Around time = Completion time - arrival time
- Waiting Time = Turn around time - burst time
| Process | Arrival Time (AT) | Burst Time (BT) | Completion Time (CT) | Turn Around Time (TAT) | Waiting Time (WT) |
|---|---|---|---|---|---|
| P1 | 0 | 6 | 11 | 11-0 = 11 | 11-6 = 5 |
| P2 | 0 | 8 | 19 | 19-0 = 19 | 19-8 = 11 |
| P3 | 0 | 5 | 5 | 5-0 = 5 | 5-5 = 0 |
Now,
- Average Turn around time = (11 + 19 + 5)/3 = 11.6 ms
- Average waiting time = (5 + 0 + 11 )/3 = 16/3 = 5.33 ms
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 | 3 ms | 1 ms |
| P3 | 7 ms | 2 ms |
Step-by-Step Execution:
Gantt chart :
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 | 9 | 9-0 = 9 | 9-6 = 3 |
| P2 | 1 | 3 | 4 | 4-1 = 3 | 3-3 = 0 |
| P3 | 2 | 7 | 16 | 16-2 = 14 | 14-7 = 7 |
- Average Turn around time = (9 + 14 + 3)/3 = 8.6 ms
- Average waiting time = (3 + 0 + 7 )/3 = 10/3 = 3.33 ms
Step 1: Input number of processes with arrival time and burst time.
Step 2: Initialize remaining times (burst times), current time = 0, and counters.
Step 3: At each time unit, add processes that have arrived into the ready queue.
Step 4: Select the process with the shortest remaining time (preempt if a shorter one arrives).
Step 5: Execute the selected process for 1 unit, reduce its remaining time, and increment current time.
Step 6: If a process completes:
Step 7: Repeat Steps 3–6 until all processes complete.
Step 8: Calculate average waiting time and turnaround time.
Step 9: Display completion, waiting, and turnaround times for each process, along with averages.
Program to implement Shortest Remaining Time First is as follows:
Enter number of processes: Avg WT: -nan Avg TAT: -nan
Advantages of SRTF Scheduling
Disadvantages of SRTF Scheduling