LearnYourBasics

Spread your knowledge

CPU scheduling is the mechanism in an operating system that decides which process gets access to the CPU and for how long multiple processes are ready to run. It ensures the CPU stays busy by selecting from the ready queue, switching processes via context switches to maximize utilization and minimize idle time. This is vital in multitasking environments where processes compete for the single CPU, helping balance fairness, response times, and throughput without one process dominating. The short-term scheduler handles it, using algorithms to pick based on criteria like arrival time, priority, or burst length, ultimately improving system performance by overlapping computation with waits for I/O or other resources.

NOTE * Many confuse CPU scheduling with general process scheduling, but CPU scheduling is a specific subset focused on allocating CPU bursts to ready processes, while process scheduling covers the broader flow from job admission to termination. CPU scheduling is exclusively handled by the Short-Term Scheduler (also called the CPU Scheduler), which operates frequently (every few milliseconds) to select and dispatch processes from the ready queue to the running state. The long-term scheduler deals with job entry, and medium-term with memory swaps, but only the short-term one directly manages CPU time slices and preemption. This distinction keeps things efficient: without the short-term scheduler’s quick decisions, the system would lag in responsive tasks like typing or web browsing. *

Types of CPU Scheduling

1. Preemptive Scheduling

2. Non-Preemptive Scheduling

  • Preemptive Scheduling: The OS can interrupt a running process at any time (via timers or priorities) to give CPU to another, ensuring no single task hogs resources. It uses time quanta or events to trigger switches, ideal for real-time or multi-user setups.

  • Non-Preemptive Scheduling: A process keeps the CPU until it finishes, blocks for I/O, or exits—no forced interrupts. It’s easier to implement without complex synchronization but can lead to convoy effects where short jobs wait behind long ones.

    Algorithms Under Each Type

    Algorithms implement the scheduling logic, categorized by type with examples showing which fits where.

    Non-Preemptive Algorithms
    • First-Come, First-Served (FCFS): Processes execute in arrival order, like a simple queue—no preemption.

    • Shortest Job First (SJF): Picks the process with the smallest CPU burst next; non-preemptive version waits for full completion.

    • Priority Scheduling (Non-Preemptive): Selects the highest-priority ready process, running it to end before others.

    Preemptive Algorithms
    • Shortest Remaining Time First (SRTF): Preemptive SJF variant—interrupts current if a shorter burst arrives.

    • Round Robin (RR): Gives each process a fixed time quantum in cycle; preemptive by timer interrupt.

    • Priority Scheduling (Preemptive): Like non-preemptive but can bump running low-priority processes for higher ones.

    • Multilevel Queue Scheduling: Divides ready queue into levels (e.g., foreground vs. background) with fixed algorithms per queue; often preemptive within levels.

    • Multilevel Feedback Queue (MLFQ): Adaptive queues where processes move levels based on behavior (e.g., demote CPU hogs); typically preemptive with time slices varying by level.

Scroll to Top