Contents

Scheduling Algorithms in OS

Introduction

Imagine managing a busy coffee shop: some customers demand urgent service (like espresso orders), while others wait patiently (like a large batch brew). Operating systems use scheduling algorithms to similarly manage processes. Let’s explore the two broad categories: preemptive and non-preemptive scheduling.

Preemptive Scheduling: The Interrupter

What It Does

  • The OS can pause a running process to prioritize another.
  • Processes are interrupted based on priority, time limits, or events.
  • Ex: A traffic light interrupting a green signal for an ambulance (higher priority).
  • Ex: A video call app is running, but the OS pauses it to handle a sudden mouse click.

Pros & Cons

  • Flexibility: Critical tasks get immediate attention.
  • Better for real-time systems (e.g., robotics).
  • Overhead: Frequent switching slows performance.

Common Preemptive Algorithms

  1. Round Robin (RR)
  2. Shortest Remaining Time First (SRTF)
  3. Priority Preemptive Scheduling
  4. Multilevel Queue Scheduling
  5. Multilevel Feedback Queue

Non-Preemptive Scheduling: The Completer

What It Does

  • The OS lets a process run to completion once it starts.
  • No interruptions unless the process voluntarily gives up the CPU (e.g., waits for I/O).
  • Ex: A buffet line: Once you start filling your plate, others wait until you’re done.
  • Ex: A printer finishes a job completely before starting the next, even if a new request arrives.

Pros & Cons

  • Simplicity: Less overhead for the OS.
  • Predictable: Processes finish in a set order.
  • Poor responsiveness: Long tasks block others.

Common Non-Preemptive Algorithms

  1. First-Come, First-Served (FCFS)
  2. Shortest Job First (SJF)
  3. Priority Non-Preemptive Scheduling
  4. Highest Response Ratio Next (HRRN)

Key Differences

FeaturePreemptiveNon-Preemptive
InterruptionYes (OS forces)No (process finishes/yields)
OverheadHighLow
ResponsivenessHighLow
Use CasesReal-time systems, multitaskingBatch processing, simple tasks

Why Does This Matter?

  • Preemptive ensures fairness and responsiveness (e.g., your phone handling calls and apps).
  • Non-Preemptive guarantees task completion (e.g., printing documents in order).

FAQ

Q: Can an algorithm be both preemptive and non-preemptive?

No! They’re mutually exclusive. However, some systems combine both (e.g., preemptive for high-priority tasks).

Q: Which is better?

Depends on the goal:

  • Preemptive: For interactive systems (desktops, servers).
  • Non-Preemptive: For stability (embedded systems, batch jobs).

Q: What’s “voluntary yielding” in non-preemptive?

A process may give up the CPU on its own (e.g., waiting for user input).