OS Notes
Complete explanation of Multilevel Queue CPU scheduling with queue partitioning, fixed priority between queues, scheduling within queues, and practical applications in modern operating systems.
Introduction
In a large company, different types of work require different handling. The CEO's requests go through an executive assistant and get immediate attention. Regular employee requests go through a ticketing system. Maintenance requests go through a different queue entirely. Each type of work has its own queue with its own rules. This is exactly how multilevel queue scheduling works.
Multilevel Queue Scheduling partitions the ready queue into several separate queues. Each queue has its own scheduling algorithm, and there is a fixed scheduling policy between queues (usually priority-based). Processes are permanently assigned to a queue based on properties like process type, priority, or memory requirements.
How It Works
The key idea is classification. Processes are divided into categories, and each category gets its own queue with its own scheduling algorithm:
| │ Queue 1 | System Processes [Priority: Highest]│ |
| │ Scheduling | Priority-based │ |
| │ Queue 2 | Interactive Processes [Priority: High] │ |
| │ Scheduling | Round Robin (quantum = 8ms) │ |
| │ Queue 3 | Background Batch [Priority: Medium] │ |
| │ Scheduling | FCFS │ |
| │ Queue 4 | Student Processes [Priority: Low] │ |
| │ Scheduling | FCFS │ |
Rules of Multilevel Queue Scheduling
- Permanent assignment — A process stays in its assigned queue forever. It cannot move between queues.
- Inter-queue scheduling — Usually fixed-priority preemptive. The CPU serves the highest-priority non-empty queue.
- Intra-queue scheduling — Each queue can use a different algorithm internally (RR, FCFS, SJF, etc.)
Detailed Example
Consider a system with three queues:
- Queue 1 (System): Priority scheduling, highest priority
- Queue 2 (Interactive): Round Robin with quantum = 4ms
- Queue 3 (Batch): FCFS, lowest priority
| Process | Queue | Arrival | Burst |
|---|---|---|---|
| P1 | System | 0 | 4 |
| P2 | Interactive | 0 | 8 |
| P3 | Batch | 0 | 12 |
| P4 | System | 5 | 2 |
| P5 | Interactive | 3 | 6 |
Execution Trace
| Time 0-4 | P1 runs (System queue, highest priority) |
| Time 4-5 | P2 runs (Interactive, RR quantum starts) |
| Time 5-7 | P4 arrives and preempts! (System queue has priority) |
| Time 7-11 | P2 resumes (Interactive, 4ms quantum) |
| Time 11-15 | P5 runs (Interactive, RR — P2 exhausted quantum at time 11) |
| Time 15-18 | P2 runs (back from queue, remaining 3ms) |
| Time 18-20 | P5 runs (remaining 2ms) |
| Time 20-32 | P3 finally runs (Batch, FCFS — only when all higher queues empty) |
Gantt Chart
Notice how P3 (batch process) had to wait until time 20 despite arriving at time 0. This illustrates the potential starvation problem in multilevel queue scheduling.
Scheduling Between Queues
There are two common approaches for inter-queue scheduling:
Fixed Priority (Preemptive)
The most common approach. Higher-priority queues always preempt lower ones. A batch process only runs when all system and interactive queues are empty. This maximizes responsiveness for important processes but can starve lower queues.
Time Slicing Between Queues
Each queue gets a percentage of CPU time. For example:
- System queue: 20% of CPU time
- Interactive queue: 60% of CPU time
- Batch queue: 20% of CPU time
This prevents starvation but reduces responsiveness for high-priority processes.
Comparison with Single Queue
| Aspect | Single Queue | Multilevel Queue |
|---|---|---|
| Complexity | Simple | More complex |
| Process types | All treated alike | Different treatment per type |
| Algorithm | One for all | Different per queue |
| Flexibility | Limited | Highly configurable |
| Starvation risk | Depends on algorithm | Higher with fixed priority |
| Real-world use | Simple systems | All modern OS |
Practical Example: Unix/Linux
Unix-like systems traditionally use a multilevel queue structure:
| Priority 0-49 | Real-time processes (SCHED_FIFO, SCHED_RR) |
| Priority 50-99 | Kernel threads |
| Priority 100-139 | Normal user processes (SCHED_NORMAL/CFS) |
A real-time audio processing thread (priority 30) will always preempt a normal user process (priority 120) like a text editor or web browser.
Limitations
The biggest limitation of multilevel queue scheduling is its rigidity. Once a process is assigned to a queue, it stays there permanently. But what if a process changes behavior? A CPU-bound process might become I/O-bound, or a batch job might become urgent. The process cannot move to a more appropriate queue.
This limitation is addressed by the Multilevel Feedback Queue (covered separately), which allows processes to move between queues based on their behavior.
Real-World Analogy
Multilevel queue scheduling is like a hospital with different departments. Emergency patients go to the ER (highest priority, immediate attention). Scheduled surgery patients go to the surgical ward (high priority, Round Robin by appointment time). Outpatients go to the general clinic (lower priority, FCFS). A patient assigned to outpatient care cannot jump to the ER queue just because they have been waiting long — they are permanently assigned to their category based on their initial assessment.
Key Takeaways
- Multilevel queue scheduling uses multiple separate queues for different process categories
- Each queue can have its own scheduling algorithm (RR, FCFS, Priority, etc.)
- Processes are permanently assigned to queues and cannot move between them
- Inter-queue scheduling is typically fixed-priority preemptive (highest queue served first)
- Time slicing between queues can prevent starvation of lower-priority queues
- The rigidity of permanent queue assignment is the main drawback
- All modern operating systems use some form of multilevel queue scheduling
- The Multilevel Feedback Queue addresses the limitation by allowing queue migration
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Multilevel Queue Scheduling.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, cpu, scheduling, multilevel, queue
Related Operating Systems Topics