DEV Community

Aditya
Aditya

Posted on

Round Robin vs SJF: a worked scheduling example you can redo by hand

Scheduling questions in OS exams look scary, but the method is the same every time: draw the Gantt chart, then read waiting time and turnaround time off it.

Take 3 processes, all arriving at time 0:

Process Burst
P1 6
P2 2
P3 4

SJF (non-preemptive): run the shortest first: P2 (0-2), P3 (2-6), P1 (6-12).
Waiting times: P2 = 0, P3 = 2, P1 = 6. Average = 8/3 = 2.67.

Round Robin, quantum = 2: P1 (0-2), P2 (2-4), P3 (4-6), P1 (6-8), P3 (8-10), P1 (10-12).
Waiting time = finish - burst: P1 = 12 - 6 = 6, P2 = 4 - 2 = 2, P3 = 10 - 4 = 6. Average = 14/3 = 4.67.

So SJF gives the lower average wait here, but it can starve long jobs. Round Robin is fairer and has better response time, at the cost of more context switches.

Tips: always list arrival times first, mark the quantum on the chart, and check that the total of all bursts equals the last finish time.

I also made a full OS revision video (processes, scheduling, deadlock, memory, file systems) in Hinglish, about 96 min: https://www.youtube.com/watch?v=RSR2sqyR5pE

More notes and videos on Telegram: https://t.me/techvaniai

Top comments (0)