Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Session 2.5: Preemptive and multilevel scheduling: RR, SRTF, Priority, MLQ, MLFQ

Taking the CPU away: round robin and the time quantum, shortest-remaining-time-first, preemptive priority, and multilevel queues that adapt to process behaviour.

Module 2 1.5 hours Theory CO2
← Before
2.4 Scheduling I
FCFS, SJF, Priority
You are here
2.5 Preemptive and multilevel scheduling: RR, SRTF, Priority, MLQ, MLFQ
Module 2 · Process, Scheduling, Threads and Deadlocks
Next →
2.6 Deadlocks
When processes block forever

Learning objectives

By the end of this session you should be able to:

  • Solve Round Robin problems and explain how the quantum affects performance.
  • Solve SRTF and preemptive-priority problems with arrival times.
  • Describe multilevel queue scheduling and the two ways of scheduling between queues.
  • Explain how a multilevel feedback queue promotes and demotes processes.
  • Compare all six syllabus algorithms on preemption, goal and risk.

Lecture notes

1. Round Robin (RR)

Designed for time-sharing. The ready queue is a circular FIFO; each process gets a small unit of CPU time, the time quantum q (typically 10–100 ms). If it hasn't finished when the quantum expires, the timer interrupt preempts it and it goes to the tail of the ready queue.

Worked example — RR with q = 4

P1 = 24, P2 = 3, P3 = 3, all at time 0.

Gantt: P1 [0–4] · P2 [4–7] · P3 [7–10] · P1 [10–14] · P1 [14–18] · … · P1 [26–30].

WT: P1 = 10 − 4 = 6, P2 = 4, P3 = 7 → average 17/3 ≈ 5.67 ms. Response times are 0, 4, 7 — every process starts quickly.

Simulator — Round RobinEdit the inputs, press Run, then Step or Play.

Choosing the quantum

  • q very large → RR becomes FCFS.
  • q very small → too many context switches; overhead dominates.
  • Rule of thumb: q should be large compared with the context-switch time (q = 10 ms vs switch < 10 µs) and about 80% of CPU bursts should be shorter than q.

With n processes and quantum q, no process waits more than (n − 1) × q before its next turn — RR guarantees response time, at the cost of a higher average turnaround than SJF.

2. Shortest-Remaining-Time-First (SRTF) — preemptive SJF

When a new process arrives whose burst is shorter than what remains of the running process, the running process is preempted.

Worked example — SRTF

(AT, BT): P1 (0, 8), P2 (1, 4), P3 (2, 9), P4 (3, 5).

t = 0 P1 starts. t = 1 P2 arrives (4 < 7 remaining) → preempt. P2 runs to 5. Then P4 (5) beats P1 (7) → P4 to 10. P1 to 17, P3 to 26.

Gantt: P1 [0–1] · P2 [1–5] · P4 [5–10] · P1 [10–17] · P3 [17–26].

WT: P1 = 17 − 0 − 8 = 9, P2 = 0, P3 = 26 − 2 − 9 = 15, P4 = 10 − 3 − 5 = 2 → average 6.5 ms (non-preemptive SJF gives 7.75).

Simulator — SRTFEdit the inputs, press Run, then Step or Play.

3. Preemptive priority

When a process arrives with a higher priority than the running one, the running process is preempted immediately. Starvation is still possible; aging still applies. Try the same data with both versions in the simulator:

Simulator — Preemptive priorityEdit the inputs, press Run, then Step or Play.

4. Multilevel Queue (MLQ) scheduling

Processes are permanently assigned to one of several queues by type, each with its own algorithm. For example:

1 · System processes — highest priority
2 · Interactive processes — RR
3 · Interactive editing processes — RR
4 · Batch processes — FCFS
5 · Student processes — lowest priority

Scheduling between queues is either fixed-priority preemptive (a lower queue runs only if all higher queues are empty — risk of starvation) or time-slicing (e.g. 80% of CPU to foreground RR, 20% to background FCFS).

5. Multilevel Feedback Queue (MLFQ)

MLFQ lets processes move between queues based on their behaviour: a process that uses too much CPU is moved down; one that waits too long is moved up (aging). This favours short and interactive jobs without knowing burst lengths in advance.

Three queues: Q0 RR with q = 8 ms, Q1 RR with q = 16 ms, Q2 FCFS. Q1 runs only when Q0 is empty; Q2 only when Q0 and Q1 are empty.

Every new process enters Q0.

A process with an 5 ms burst finishes within its 8 ms quantum in Q0 — interactive jobs stay at the top and respond quickly.

A process that uses its full 8 ms is moved down to Q1, where it gets 16 ms when Q0 is empty.

If it still doesn't finish, it drops to Q2 and runs FCFS in leftover CPU time — long CPU-bound jobs sink.

A process that has waited too long in a low queue is promoted back up, preventing starvation.

An MLFQ is defined by: the number of queues, the algorithm for each queue, when to upgrade a process, when to demote it, and which queue a new process enters. It is the most general — and most complex — scheduler; variants are used by Windows, macOS and older Linux kernels.

6. Summary of all six syllabus algorithms

AlgorithmPreemptive?OptimisesRisk
FCFSNoSimplicityConvoy effect
SJFNoAverage WT (optimal)Starvation of long jobs
PriorityNo / YesImportanceStarvation → aging
Round RobinYes (quantum)Response time, fairnessOverhead if q too small
SRTFYes (on arrival)Average WTStarvation; needs prediction
MLQ / MLFQYesMix of process typesComplex to tune

VideoBytes

Round Robin and SRTF — worked examples

Video coming soon

Round Robin and SRTF — worked examples

Recorded by Dr. Krithika L.B. Slot m2-rr-srtf

Multilevel and feedback queues

Video coming soon

Multilevel and feedback queues

Recorded by Dr. Krithika L.B. Slot m2-mlq-mlfq

Interactive lessons

Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.

Lab connection

Check your understanding

Answer each question in your own words first, then reveal the model answer.

Revealed 0
P1 = 10, P2 = 4, P3 = 6 at time 0, RR with q = 3. Draw the Gantt chart.

P1 0–3, P2 3–6, P3 6–9, P1 9–12, P2 12–13, P3 13–16, P1 16–19, P1 19–20. CT: P1 20, P2 13, P3 16 → WT 10, 9, 10 → average 9.67.

What happens to RR if the quantum is larger than every burst?

No process is ever preempted by the timer, so RR behaves exactly like FCFS.

In SRTF, when is the scheduler invoked?

Whenever a process arrives (to compare its burst with the remaining time of the running process) and whenever the running process finishes or blocks.

Why does MLFQ favour interactive processes?

Interactive processes use short CPU bursts and give up the CPU before their quantum ends, so they stay in the high-priority queues; CPU-bound processes use full quanta and are demoted.

Give the worst-case wait for a ready process under RR with 5 processes and q = 20 ms.

(n − 1) × q = 4 × 20 = 80 ms (ignoring switch overhead).

Key takeaways

  • RR: circular queue + quantum; small q → overhead, large q → FCFS; bounded response time.
  • SRTF preempts on arrival of a shorter job; preemptive priority preempts on a higher priority.
  • MLQ fixes a process to one queue; MLFQ moves processes between queues using demotion and aging.

Where this leads

Scheduling decides who gets the CPU. But processes also hold other resources — locks, files, printers. If each holds one and waits for another's, nobody proceeds: deadlock.

Continue to 2.6 — Deadlocks →