Process Scheduling Algorithms
Process Scheduling Algorithms
Process Scheduling determines the order in which processes are executed by the CPU.
Goal: maximize CPU utilization, minimize waiting and turnaround times, and ensure
fairness.
Non-preemptive
Processes executed in order of arrival.
Example:
Gantt Chart: P1 | P2 | P3
Waiting Time:
P1 = 0
P2 = 5 – 1 = 4
P3 = (5+3) – 2 = 6
Avg WT = (0+4+6)/3 = 3.33
4. Shortest Job First (SJF)
Non-preemptive
Process with the shortest burst time is selected.
Same Example:
Order: P1 | P2 | P3 → (as P2 has to wait till P1 finishes)
Improves Avg Waiting Time when short processes are executed first.
Example Exercise:
Preemptive
Each process gets CPU for a time slice (quantum).
After quantum expires, process goes to the back of the queue.
Example:
Quantum = 2
Processes: P1(5), P2(3), P3(1)
Gantt Chart: P1 | P2 | P3 | P1 | P2 | P1
Calculate WT and TAT
7. Priority Scheduling
Example:
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 2
Execution Order: P2 → P3 → P1
Summary Table
Algorithm Preemptive Avg WT Suitable for
FCFS No Medium Simple batch systems
SJF No Low Predictable jobs
SRTF Yes Lowest Optimal, complex to implement
RR Yes Fair Time-sharing systems
Priority Both Varies Real-time systems
Practice Exercises
Exercise 1: FCFS & SJF Comparison
Given:
Processes:
P1 (0, 6)
P2 (1, 2)
P3 (2, 4)
P4 (3, 1)
Use Gantt chart to calculate WT, TAT.
Processes: