Chapter 03 · OS
CPU Scheduling Algorithms
4 topics · 1 sections · beginner-friendly study notes · Updated
The CPU scheduler picks which ready process runs next.
This chapter defines the criteria (waiting, turnaround, response time) and works through FCFS, SJF/SRTF, Priority, Round Robin and multilevel queues with Gantt-chart numericals in GATE style.
Scheduling numericals (average waiting time, Gantt chart) are among the most repeated GATE question types.
Linux CFS, Windows priority scheduling, real-time systems, cloud schedulers and fairness tuning.
Scheduling Criteria
Arrival time (AT) is when a process enters the ready queue; burst time (BT) is CPU time needed; completion time (CT) is when it finishes. Turnaround time TAT = CT - AT. Waiting time WT = TAT - BT. Response time RT = first CPU time - AT.
In short: TAT is total time in the system, WT is time spent idle in the ready queue, RT is how long until the first reply.
Think about it
Every numerical reduces to these formulae applied to a correct Gantt chart.
Goals
- 1maximize CPU utilization and throughput
- 2minimize turnaround, waiting and response time
Preemptive scheduling can take the CPU away (timer or higher-priority arrival); non-preemptive lets a process run until it blocks or terminates.
For CPU-only processes in non-preemptive scheduling, RT = WT.
Scheduling decisions occur when a process switches Running→Waiting, Running→Ready, Waiting→Ready or terminates; only the first and last are possible in a non-preemptive system.
The dispatcher’s delay is dispatch latency.
Always draw the Gantt chart, note idle CPU gaps, and compute averages last.
Key points
- Gantt chart: Timeline showing which process runs during each interval.
- Throughput: Number of processes completed per unit time.
- Convoy effect: Short processes stuck behind a long CPU-bound process in FCFS.
- TAT = CT - AT; WT = TAT - BT; RT = (first run start) - AT.
- Average over all processes at the end; show units.
FCFS and SJF Scheduling
FCFS runs processes in order of arrival (non-preemptive). SJF picks the ready process with the smallest next CPU burst (non-preemptive). SRTF is the preemptive version: whenever a new process arrives with burst shorter than the remaining time of the running one, it preempts.
In short: FCFS is a queue at a ticket counter. SJF/SRTF always serves the shortest job first, which gives low average waiting.
Think about it
They illustrate the trade-off between simplicity, fairness and optimality.
FCFS is simple and starvation-free but suffers from the convoy effect and can have a high average waiting time.
SJF is provably optimal for minimum average waiting time among non-preemptive algorithms, and SRTF is optimal among preemptive ones.
The difficulty is knowing the next burst length; it is predicted with exponential averaging: τ(n+1) = α·t(n) + (1-α)·τ(n).
SJF/SRTF can starve long processes.
Ties are normally broken by earlier arrival (or lower process ID).
In SRTF a process that arrives with equal remaining time does not preempt, as it would only add a switch.
Key points
Read more
Priority & Multilevel Feedback
Priority scheduling gives the CPU to the highest-priority ready process (preemptive or non-preemptive; read whether a smaller number means higher priority). Multilevel queue scheduling partitions the ready queue into separate queues with fixed priority between queues; the Multilevel Feedback Queue (MLFQ) additionally lets processes move between queues based on observed behaviour.
In short: VIPs go first; in the feedback version jobs that hog the CPU are demoted and jobs that wait long are promoted.
Think about it
Real systems need to favour interactive or real-time tasks.
MLFQ
new jobs enter the top queue with a short quantum (e.
g.
Q0: RR q=8, Q1: RR q=16, Q2: FCFS); a job that uses its whole quantum is demoted, a job that blocks for I/O stays high, and long-waiting jobs are promoted (aging).
This favours I/O-bound and interactive jobs and approximates SJF without knowing burst lengths.
An MLFQ is defined by: number of queues, algorithm per queue, rule to upgrade, rule to demote and rule for the initial queue.
A fixed multilevel queue (system > interactive > batch) keeps each process permanently in its queue and can starve lower queues unless time slices are shared between queues.
Priorities can be internal (burst length, memory needs) or external (importance, payment).
SJF is priority scheduling with priority = 1 / next burst.
The major problem is starvation of low-priority processes; aging gradually increases the priority of waiting processes to fix it.
Another issue is priority inversion: a high-priority task waits for a lock held by a low-priority one while a medium-priority task runs; priority inheritance temporarily boosts the lock holder.
Key points
- Aging: Gradually raising priority of long-waiting processes to prevent starvation.
- Priority inversion: High-priority process blocked by lower-priority one holding a resource.
- Priority inheritance: Lock holder temporarily takes the priority of the blocked high-priority process.
- Multilevel queue: Separate ready queues per process class with fixed priority between queues.
- MLFQ: Multilevel feedback queue: processes move between queues by behaviour.
- Demotion: Moving a process to a lower-priority queue after using its full quantum.
- I/O-bound vs CPU-bound: Many short CPU bursts between I/O waits vs long CPU bursts with little I/O.
- MLFQ example: Q0 RR q=8, Q1 RR q=16, Q2 FCFS. A 30-unit CPU-bound job runs 8 in Q0, 16 in Q1, then the remaining 6 in Q2; a short interactive burst of 5 finishes inside Q0 and keeps its high priority.
Example
Codepriority (smaller = higher), non-preemptive: P1 (AT0, BT4, pr2), P2 (AT1, BT3, pr1), P3 (AT2, BT2, pr3). P1 runs 0-4; then P2 (pr1) 4-7; then P3 7-9. WT: P1 0, P2 3, P3 5 → average 8/3 ≈ 2.67.
Round Robin Scheduling
Round Robin (RR) is preemptive FCFS with a fixed time quantum q. Each process gets the CPU for up to q units, then goes to the tail of the ready queue.
In short: Everyone gets a short turn in a circle.
Think about it
It is the basis of time-sharing and interactive scheduling.
With n ready processes and quantum q, no process waits more than (n-1)q before its next turn.
If q is very large, RR degenerates into FCFS; if q is very small, context-switch overhead dominates.
A good rule
q slightly larger than the typical interactive burst (about 80% of bursts should finish within q).
RR gives better response time than SJF but usually higher average turnaround.
For a numerical, keep the queue order carefully: a process that arrives at the same instant a quantum ends is normally queued before the preempted process (state the convention if the question is ambiguous).
Key points
Solved examples
Processes: P1 (AT 0, BT 8), P2 (AT 1, BT 4), P3 (AT 2, BT 9), P4 (AT 3, BT 5). Compute average waiting time and turnaround time for FCFS.
- P1: AT0 BT8
- P2: AT1 BT4
- P3: AT2 BT9
- P4: AT3 BT5
Average WT and TAT
Formula Applied:—Approach note: Construct the Gantt chart first, then derive CT, TAT and WT in a table.
Same processes as above. Find the average waiting time using non-preemptive SJF and using preemptive SRTF.
- P1: AT0 BT8
- P2: AT1 BT4
- P3: AT2 BT9
- P4: AT3 BT5
Average WT for SJF and SRTF
Formula Applied:—Approach note: For SRTF re-evaluate at every arrival and compare against the remaining (not original) burst of the running process.
Round Robin with quantum q = 2. All arrive at t = 0: P1 (BT 5), P2 (BT 3), P3 (BT 1). Find waiting, turnaround and response times.
- q = 2
- BT: P1 5, P2 3, P3 1
- All AT = 0
WT, TAT, RT per process and averages
Formula Applied:—Approach note: Update the ready queue after each slice and put the preempted process at the tail.
Processes all arrive at 0: P1 BT=6, P2 BT=2, P3 BT=8. Quantum = 3. Find average waiting time for Round Robin.
Average WT
Formula Applied:—Approach note: Rebuild the ready queue after each quantum; do not reorder arbitrarily.
Real-world applications
Using CPU Scheduling Algorithms in real projects
Linux CFS, Windows priority scheduling, real-time systems, cloud schedulers and fairness tuning.
Common mistakes
❌ Myth: SJF is always practical because it is optimal.
Why this is wrong: The OS cannot know the exact next CPU burst in advance; only estimates are possible.
✅ Verified Truth: SJF is optimal for average waiting time in theory, but it needs burst prediction and can starve long jobs.
⚠️ Exam Tip: Mention exponential averaging and starvation.
❌ Myth: Round Robin always gives the lowest average waiting time.
Why this is wrong: RR often has higher average waiting and turnaround than SJF, but better response time.
✅ Verified Truth: RR is best for response time and fairness, not minimum waiting time.
⚠️ Exam Tip: Match the algorithm to the metric in the question.
❌ Myth: Waiting time is the same as response time.
Why this is wrong: Waiting time counts all time in the ready queue; response time counts only until the first run.
✅ Verified Truth: They are equal only for non-preemptive CPU-only processes.
⚠️ Exam Tip: Use the formulae RT = first start - AT, WT = TAT - BT.
Revision notes
The CPU scheduler picks which ready process runs next. This chapter defines the criteria (waiting, turnaround, response time) and works through FCFS, SJF/SRTF, Priority, Round Robin and multilevel queues with Gantt-chart numericals in GATE style.
High-Yield Quick Revision Points
- TAT = CT - AT; WT = TAT - BT; RT = first start - AT
- FCFS: convoy effect; SJF/SRTF: optimal avg WT but starvation
- Priority: starvation fixed by aging; inversion fixed by inheritance
- RR: (n-1)q max wait; large q → FCFS, tiny q → overhead
- MLFQ: demote CPU hogs, keep I/O-bound jobs high
- Always draw the Gantt chart and mark idle gaps
Practice questions
Which scheduling algorithm gives minimum average waiting time for a given set of processes (all known in advance)?
The convoy effect is most associated with:
Starvation in priority scheduling is solved by:
In Round Robin with n processes in the ready queue and quantum q, the maximum time a process waits before getting the CPU again is:
A process has AT = 4, BT = 6 and completes at time 20. Its waiting time is:
Solved questions from this chapter
Real doubts students asked — full working and final answer, some with a video.