Shortest Job First (SJF) Scheduling Algorithm
What is SJF Scheduling?
SJF Scheduling is a non-preemptive scheduling algorithm that prioritizes the process with the shortest burst time.
How SJF Scheduling Works
- Sort the processes in ascending order of their burst times.
- Execute the process with the shortest burst time first.
- Once a process starts execution, it runs to completion.
Example Calculation
Process | Arrival Time | Burst Time |
---|---|---|
P1 | 0 | 5 |
P2 | 0 | 3 |
P3 | 0 | 1 |
P4 | 0 | 2 |
Gantt Chart
Time | Process |
---|---|
0-1 | P3 |
1-3 | P4 |
3-6 | P2 |
6-11 | P1 |
Calculation of Waiting Time and Turnaround Time
Process | Arrival Time | Burst Time | Completion Time | Turnaround Time | Waiting Time |
---|---|---|---|---|---|
P3 | 0 | 1 | 1 | 1 | 0 |
P4 | 0 | 2 | 3 | 3 | 2 |
P2 | 0 | 3 | 6 | 6 | 3 |
P1 | 0 | 5 | 11 | 11 | 6 |
Average Waiting Time and Turnaround Time
Average Waiting Time = (0 + 2 + 3 + 6) / 4 = 11 / 4 = 2.75
Average Turnaround Time = (1 + 3 + 6 + 11) / 4 = 21 / 4 = 5.25
No comments:
Post a Comment