Lecture Notes: Pre-emptive Shortest Job First (SJF) Scheduling
Overview of Pre-emptive SJF (RT)
- Preemptive SJF is a CPU scheduling algorithm.
- Also known as Shortest Remaining Time (SRT).
- Prioritizes processes with the shortest remaining execution time.
Process Arrival Timeline
- At time 0: Only process P0 is present.
- At time 2: Process P1 arrives.
- P1 has a burst time shorter than P0's remaining time.
- Preempt P0, enqueue P1.
- At time 5: Process P2 arrives.
- P2 has a shorter remaining time than P1.
- Preempt P1, enqueue P2.
- At time 7: Process P3 arrives.
- Compare with P2's remaining time; P2 is shorter.
- Continue P2 until completion.
- At time 10: Process P4 arrives.
- Compare with the remaining processes P0, P1, P3.
- Continue with P1 as it has the shortest remaining time.
Detailed Execution Steps
- Time 0 - 2:
- P0 executes for 2 milliseconds, 14 ms remaining.
- Time 2 - 5:
- P1 executes for 3 milliseconds, 7 ms remaining.
- P0 is placed back in the queue.
- Time 5 - 8:
- P2 executes, finishing in 3 ms as it had the shortest time.
- Time 8 - 15:
- P1 resumes execution and completes.
- Time 15 - 23:
- P3 executes for 8 ms and completes.
- Time 23 - 35:
- P4 executes, completing its 12 ms burst.
- Time 35 - 49:
- P0 resumes and completes the remaining execution.
Key Points
- Preemption occurs when a new process arrives with a shorter burst time than the current executing process.
- Final Execution Order: P0 → P1 → P2 → P3 → P4
- Completion times:
- P1 completes at 15
- P3 completes at 23
- P4 completes at 35
- P0 completes at 49
This scheduling ensures processes with shorter remaining times get prioritized, optimizing overall process completion time.