Process Scheduling Algorithms – Short Notes
1. Introduction to Process Scheduling
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.
2. Key Scheduling Criteria
CPU Burst Time: Time the process needs on CPU.
Arrival Time: When the process enters the ready queue.
Waiting Time (WT): Time spent waiting in the queue.
Turnaround Time (TAT): Completion time – Arrival time.
Response Time: First response – Arrival time.
3. First-Come, First-Served (FCFS)
Non-preemptive
Processes executed in order of arrival.
Example:
Process Arrival Time Burst Time
P1 0 5
P2 1 3
P3 2 8
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.
5. Shortest Remaining Time First (SRTF)
Preemptive version of SJF
If a new process arrives with a shorter remaining time, it preempts.
Example Exercise:
Arrival: P1(0,8), P2(1,4), P3(2,2), P4(3,1)
Try to build Gantt Chart, compute WT and TAT.
6. Round Robin (RR)
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
Each process assigned a priority; lower number = higher priority.
Can be preemptive or non-preemptive.
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:
Process Arrival Burst
P1 0 7
P2 1 5
P3 3 1
Compute WT and TAT for both FCFS and SJF.
Compare the average waiting and turnaround times.
Exercise 2: Round Robin
Processes: P1(Arrival=0, Burst=5), P2(0,3), P3(1,6)
Quantum = 2
Draw Gantt Chart.
Compute WT, TAT for each.
Exercise 3: SRTF Calculation
Processes:
P1 (0, 6)
P2 (1, 2)
P3 (2, 4)
P4 (3, 1)
Use Gantt chart to calculate WT, TAT.
Exercise 4: Priority Scheduling
Processes:
Process Burst Priority
P1 4 2
P2 3 1
P3 1 3
Use non-preemptive scheduling