OPERATING SYSTEMS/Student Engineering Notebook
Page 08·notes
CPU SCHEDULING ALGORITHMS—~24 MIN READ·GATE CS LENS

FCFS & Round Robin Scheduling: Gantt Charts & Time Quantum

“Explore the Convoy Effect, Time Quantum trade-offs, and live Gantt charts.”

1.FCFS & The Convoy Effect

First-Come, First-Served (FCFS) is the simplest non-preemptive algorithm: whoever arrives first in the ready queue is given the CPU until completion.

The Convoy Effect: If a long CPU-bound process arrives first, all subsequent short I/O-bound processes are forced to wait behind it. This drastically drags down average waiting time and leaves I/O devices sitting idle.

2.Round Robin (RR) with Time Quantum

Round Robin (RR) is designed specifically for time-sharing systems. The CPU is allocated to each ready process for a small slice of time called the Time Quantum (q).

If the process's burst exceeds q, it is preempted and inserted at the tail of the Ready Queue.

If q is extremely large (q → ∞), RR degenerates into simple FCFS. If q is extremely small (q → 0), context-switch overhead dominates.

WORKED NUMERICAL · STUDENT DERIVATION✎ Key Takeaway: Tie-break rule is where 80% of students lose marks: New arrivals at time t enter the Ready Queue BEFORE the process preempted at time t.

3. Solved Numerical: Round Robin Gantt Chart & Waiting Time

Problem Statement:
Consider three processes P1, P2, and P3 arriving at time 0, 1, and 2 with burst times 5, 3, and 1 respectively. The CPU is allocated using Round Robin scheduling with time quantum q = 2 ms. Determine the exact Ready Queue transitions at each preemption point, construct the execution Gantt chart, and compute the Turnaround Time (TAT) and Waiting Time (WT) for each process along with Average Waiting Time.
P1 (AT, BT)AT = 0 ms, BT = 5 msP2 (AT, BT)AT = 1 ms, BT = 3 msP3 (AT, BT)AT = 2 ms, BT = 1 msTime Quantum (q)q = 2 ms
✎ Hand-Sketched Execution Gantt Chart (q = 2 ms):P102P24P35P17P28P19↳ t=2: P3 arrives & enters queue BEFORE preempted P1↳ P3 exits here (needed only 1 ms)
Step 1: Ready Queue Trace & Tie-Breaking Rule

At t=0, only P1 has arrived → P1 runs for full quantum q=2 (remaining BT = 3). During this interval, P2 arrives at t=1, and P3 arrives at exactly t=2. Crucial Invariant: When P1 quantum expires at t=2, newly arrived P3 enters the queue BEFORE preempted P1. Queue becomes: [P2, P3, P1].

Ready Queue at t = 2: [P2, P3, P1]
↳ Result: P1 remaining BT = 3
Step 2: Dispatching P2 and P3

t=2 to 4: P2 runs for 2 ms (remaining BT = 1). Re-queued at tail. Ready Queue becomes: [P3, P1, P2]. t=4 to 5: P3 needs only 1 ms ≤ q. It runs for 1 ms and terminates at t=5. Calls exit(), no re-queueing! Ready Queue becomes: [P1, P2].

P3 Completion Time CT = 5 ms
↳ Result: P3 finished at t = 5 ms
Step 3: Final Execution Slices

t=5 to 7: P1 runs for 2 ms (remaining BT = 1). Queue: [P2, P1]. t=7 to 8: P2 runs for its final 1 ms and terminates at t=8. Queue: [P1]. t=8 to 9: P1 runs for its final 1 ms and terminates at t=9.

P2 CT = 8 ms, P1 CT = 9 ms
↳ Result: All processes complete by t = 9 ms
Step 4: Turnaround Time (TAT) and Waiting Time (WT) Calculation

Using standard OS formulas: TAT = CT - AT and WT = TAT - BT. P1: CT = 9, TAT = 9 - 0 = 9 ms, WT = 9 - 5 = 4 ms. P2: CT = 8, TAT = 8 - 1 = 7 ms, WT = 7 - 3 = 4 ms. P3: CT = 5, TAT = 5 - 2 = 3 ms, WT = 3 - 1 = 0 ms.

Total WT = 4 + 4 + 0 = 8 ms
↳ Result: Average WT = 8 / 3 = 2.67 ms
Final Answer:Average Waiting Time = 2.67 ms (Avg TAT = 6.33 ms)
LABORATORY · INTERACTIVE SIMULATION —Concept Exploration

4. Interactive CPU Scheduling & Gantt Chart Simulator

Interact with real processes. Switch between FCFS and Round Robin, adjust the time quantum, and observe how the Gantt chart and waiting times automatically recompute.

LAB BENCH · UNIVERSAL CPU SIMULATOR

Real-time CPU Scheduler & Gantt Chart Simulator

PreemptiveRound Robin (Time Sharing)
Time Quantum (q): 2 ms
ProcessArrival (AT)Burst (BT)Completion (CT)Turnaround (TAT)Waiting (WT)
P10 ms5 ms11 ms11 ms6 ms
P21 ms3 ms10 ms9 ms6 ms
P32 ms1 ms5 ms3 ms2 ms
P43 ms2 ms9 ms6 ms4 ms
Computed Execution Gantt Chart (ROUND-ROBIN):✎ Total CPU Execution Time: 11 ms
P12ms
P22ms
P31ms
P12ms
P42ms
P21ms
P11ms
0
2
4
5
7
9
10
11
Avg Turnaround Time:7.25 ms
Avg Waiting Time:4.50 ms

Interactive simulation supporting all classic scheduling algorithms: FCFS, SJF (Non-preemptive), SRTF (Preemptive SJF), Priority (Preemptive & Non-preemptive), Round Robin, LJF, LRTF, and HRRN.

GATE LENS · EXAM PREPARATION

5. GATE Lens & Verified PYQ

Syllabus focus, recurring numerical patterns, common traps, and clearly labelled exam practice. Questions remain source-pending until an official paper and answer key are attached.

EXAM WEIGHTAGE & FOCUS:

Round Robin with arrival time tie-breaks is one of the most common 2-mark numerical question patterns in GATE CS.

recurring exam patterns:
  • •A process finishing exactly at its quantum boundary: it finishes execution and does NOT re-enter the queue.
  • •Simultaneous arrival: if a new process arrives at time t exactly when an executing process is preempted, by standard convention the newly arrived process enters the Ready Queue FIRST, followed by the preempted process.
⚠ common student traps:
  • •Forgetting the tie-breaking arrival order in the Ready queue.

Exam Practice / Source Verification Required

1 problem
GATE-style question · 2 MarksTie break rule: New arrivals enter ready queue before preempted process.

Consider three processes P1, P2, and P3 arriving at time 0, 1, and 2 with burst times 5, 3, and 1 respectively. Using Round Robin scheduling with time quantum q = 2, what is the average waiting time (in ms)?

A. 2.67 ms
B. 3.00 ms
C. 3.33 ms
D. 4.00 ms
RAPID REVIEW · NOTEBOOK SUMMARY

6. 1-Minute Panic Revision

core principle:

“FCFS = Non-preemptive, Convoy Effect. RR = Preemptive with Quantum q. Low q → high overhead; High q → FCFS.”

must-remember principles:
  • •If new process arrives at time t when P is preempted: New arrival queued before preempted process.
  • •If burst <= quantum, process finishes early and next process dispatches immediately.
critical exam pitfalls:
  • •Do not allow quantum to expire if process has less than q time remaining.
decision flow & invariants:
[ ROUND ROBIN TIME QUANTUM PREEMPTION DECISION TREE ] Process P_i is currently running on CPU: │ ▼ Remaining Burst ≤ q ? │ ┌───────┴──────────────────────┐ │ Yes │ No ▼ ▼ P_i runs for RemainingBurst P_i runs for full Quantum q Calls exit() Timer Interrupt fires! [ TERMINATES ] Preempted to Ready Queue Tail (behind newly arrived processes!)
SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Primary Academic Texts
Operating System Concepts (10th Edition)↗by Silberschatz, Galvin, Gagne · Chapter 5: CPU Scheduling (Section 5.3.1: FCFS & Section 5.3.4: Round-Robin)

Official slides covering FCFS convoy effect, RR time slice quantum selection, and context switch costs.

ACADEMIC STANDARD
Operating Systems: Three Easy Pieces (OSTEP)↗by Remzi H. Arpaci-Dusseau & Andrea C. Arpaci-Dusseau · Chapter 7: Scheduling: Introduction (FIFO & Round Robin Policies)

Full chapter analyzing response time tradeoffs between FIFO and Round Robin with Gantt charts.

ACADEMIC STANDARD
ALTERNATIVE PEDAGOGICAL PERSPECTIVES

If the textbook derivation did not click immediately, consult these targeted video lessons:

Round Robin(RR) CPU Scheduling Algorithm with ExampleGate Smashers (Varun Singla) (14 mins)

Demonstrates exactly how to maintain the ready queue without ordering bugs during preemption boundaries.

Watch Lesson↗
First Come First Serve (FCFS) CPU Scheduling Algorithm with ExampleGate Smashers (Varun Singla) (12 mins)

Walks through FCFS step-by-step with CT, TAT, WT and explains why CPU-bound jobs stall I/O devices.

Watch Lesson↗
RECOMMENDED YOUTUBE LECTURES & EDUCATORS: MODULE 3: CPU SCHEDULING ALGORITHMS

Curated lectures on Gantt Charts, Preemption, FCFS Convoy Effect, Round Robin Quantum & SJF/SRTF:

Gate Smashers · L-2.3: First Come First Serve (FCFS) CPU Scheduling↗Instructor: Varun Singla · Covers: FCFS with Arrival Times, Convoy Effect illustration, Turnaround Time and Waiting Time

Step-by-step Gantt chart calculations with zero arithmetic ambiguity.

Open YouTube↗
Gate Smashers · L-2.7: Round Robin (RR) Scheduling Algorithm with Example↗Instructor: Varun Singla · Covers: Preemptive Ready Queue queue management, Time Quantum tuning, Context Switch overhead

The most reliable demonstration of ready-queue tracking during simultaneous arrivals.

Open YouTube↗
Neso Academy · CPU Scheduling Criteria & Algorithms Playlist↗Instructor: Neso Academy · Covers: SJF vs SRTF preemption tie-breakers, Priority Scheduling with Aging, Multi-Level Feedback Queues

Structured textbook-level coverage with cleanly paced whiteboard walkthroughs.

Open YouTube↗
Knowledge Gate · CPU Scheduling GATE PYQs & Edge Cases↗Instructor: Sanchit Jain · Covers: GATE tricky problems with I/O burst interleaving, non-zero arrival times, priority ties

Intense numerical speed practice and identifying examiner traps in Gantt charts.

Open YouTube↗