4.2.10Operating Systems

Scheduling algorithms — FCFS, SJF (preemptive = SRTF), Round Robin, Priority

2,249 words10 min readdifficulty · medium2 backlinks

Core vocabulary (derive every metric, don't memorize)


Two axes that classify these algorithms

  • Preemptive vs Non-preemptive: Can the OS snatch the CPU from a running process? Non-preemptive = run to completion; Preemptive = can be interrupted.
  • Selection criterion: order of arrival? shortest burst? priority number? a fixed time slice?
Algorithm Criterion Preemptive?
FCFS arrival order No
SJF shortest burst No
SRTF shortest remaining burst Yes
Round Robin time slice (quantum) Yes
Priority priority number either

1. FCFS — First Come First Served


2. SJF — Shortest Job First (non-preemptive)


3. SRTF — Shortest Remaining Time First (preemptive SJF)


4. Round Robin (RR)


5. Priority Scheduling

Figure — Scheduling algorithms — FCFS, SJF (preemptive = SRTF), Round Robin, Priority


Flashcards

What is Turnaround Time in terms of CT and AT?
TAT=CTATTAT = CT - AT (total time present in system).
Derive Waiting Time from TAT and BT.
Time present = running + waiting, so WT=TATBTWT = TAT - BT.
Why is non-preemptive SJF optimal for average waiting time?
Total WT weights earliest jobs by largest multiplier (ni)(n-i); minimizing means smallest bursts get largest multipliers ⇒ sort ascending ⇒ shortest first.
What is the convoy effect?
In FCFS, one long job at the front forces many short jobs to wait, inflating average waiting time.
SRTF preempts when?
When a newly arrived process has remaining burst smaller than the currently running process's remaining burst.
Round Robin with q → ∞ behaves like?
FCFS (no preemption ever triggers).
Round Robin with q → 0 problem?
Excessive context-switch overhead; CPU does little useful work.
What metric does Round Robin optimize best?
Response time / fairness (no starvation).
What is starvation in Priority scheduling and its fix?
Low-priority jobs never run because higher ones keep arriving; fix is aging (raise priority with waiting time).
Which scheduler gives minimum average waiting time (no preemption)?
SJF (Shortest Job First).
Order of metrics computed from a Gantt chart?
CT first, then TAT = CT−AT, then WT = TAT−BT.

Recall Feynman: explain to a 12-year-old

Imagine one swing and a line of kids. FCFS = whoever lined up first swings until they're bored — unfair if the first kid stays forever. SJF = let kids who only want a quick push go first, so the line shrinks fast. SRTF = even mid-push, if a kid wanting just one tiny push shows up, you let them in instantly. Round Robin = everyone gets exactly 2 minutes, then back of the line — super fair, nobody's left out. Priority = teacher's pets go first, but if you wait long enough you slowly become a pet too (that's "aging"). Each rule answers the same question — who goes next? — differently.

Concept Map

decides

classified by

classified by

arrival order

shortest burst

shortest remaining

time quantum

priority number

suffers

minimizes

Gantt gives

CT minus AT

TAT minus BT

Scheduling Algorithm

Who runs next

Preemptive or not

Selection criterion

FCFS non-preemptive

SJF non-preemptive

SRTF preemptive

Round Robin preemptive

Priority either

Convoy effect

Average waiting time

Completion Time

Turnaround Time

Waiting Time

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, CPU ek hi worker hai jo ek time par ek hi kaam (process) kar sakta hai, par line mein bahut saare processes khade hain. Scheduling algorithm bas ye rule hai ki "agla number kiska?". Yahi decide karta hai ki average mein sab kitna wait karenge. Mast baat ye hai ki sirf order badal ke hi average waiting time half ho sakta hai — koi naya hardware nahi chahiye!

FCFS mein jo pehle aaya wo pehle, pura kaam khatam karke hi hatega — par agar bada job aage khada ho to peeche ke chhote jobs phass jaate hain (ye convoy effect hai). SJF bolta hai jo present hain unme se sabse chhota burst wala pehle bhejo — mathematically ye sabse kam average waiting deta hai. SRTF SJF ka preemptive version hai: beech mein bhi agar koi chhota job aa gaya, to running job se CPU cheen lo.

Round Robin sabse fair hai — har process ko ek fixed time quantum (jaise 2 unit) milta hai, phir wapas line ke peeche. Isse response time accha rehta hai aur koi starve nahi hota. Priority mein number ke hisaab se CPU milta hai, par yahan khatra hai starvation ka — low priority wala kabhi chance hi na mile. Iska ilaaj aging hai: jitna zyada wait, utni priority badhao.

Exam ke liye yaad rakho: pehle Gantt chart banao, usse CT nikalo, phir TAT=CTATTAT=CT-AT, phir WT=TATBTWT=TAT-BT. SJF/SRTF mein hamesha check karo "abhi tak kaun-kaun aa chuka hai" — sirf wahi choose kar sakte ho. Bas yahi 20% concept 80% questions cover kar dega!

Test yourself — Operating Systems

Connections