100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Preemptive vs Non-Preemptive Scheduling

Preemptive vs non-preemptive CPU scheduling compared — triggers, trade-offs, algorithms, and an interview-ready answer with code.

mediumQ11 of 224 in Operating Systems Est. time: 5 minsLast updated:
Open Code Lab

Expected Interview Answer

Preemptive scheduling lets the OS forcibly suspend a running process to give the CPU to another, while non-preemptive scheduling requires the running process to voluntarily give up the CPU when it finishes or blocks.

In preemptive scheduling, the scheduler can interrupt a running task — typically via a timer interrupt — and switch to a higher-priority or waiting task, which improves responsiveness for interactive and real-time systems but adds context-switch overhead and requires careful synchronization to avoid race conditions. In non-preemptive (cooperative) scheduling, once a process is given the CPU it keeps it until it terminates or calls a blocking operation like I/O, which simplifies scheduling logic and avoids mid-task interruption but risks a long-running or misbehaving process starving everyone else. Round robin, preemptive priority, and multilevel feedback queues are preemptive; first-come-first-served and non-preemptive shortest-job-first are classic non-preemptive algorithms. The choice is fundamentally a trade-off between responsiveness and simplicity/overhead.

  • Preemptive: better responsiveness for interactive systems
  • Preemptive: prevents any single process from monopolizing the CPU
  • Non-preemptive: simpler scheduler with no mid-task interruption
  • Non-preemptive: lower context-switch overhead

AI Mentor Explanation

In a preemptive scheduling league, the umpire can call a batsman off strike mid-over to let another batsman face a crucial ball, even if the first was not out. In a non-preemptive league, once a batsman is in, he keeps batting until he is dismissed or the innings ends, no matter how long he takes. The preemptive league keeps the game responsive to changing situations, while the non-preemptive one is simpler but risks one batsman hogging the crease.

Step-by-Step Explanation

  1. Step 1

    Trigger

    Preemptive: a timer interrupt or higher-priority task arrival can force a switch at any time.

  2. Step 2

    Voluntary yield

    Non-preemptive: the running process only releases the CPU when it finishes or blocks on I/O.

  3. Step 3

    Scheduler decision

    Preemptive schedulers re-evaluate readiness on every interrupt; non-preemptive ones only decide when the CPU is freed.

  4. Step 4

    Trade-off

    Preemption buys responsiveness at the cost of context-switch overhead and synchronization complexity.

What Interviewer Expects

  • Clear definition of what "preempt" means in this context
  • Naming concrete algorithms on each side (round robin vs FCFS)
  • Discussion of responsiveness vs overhead trade-off
  • Mention of synchronization risk introduced by preemption

Common Mistakes

  • Saying preemptive scheduling is always strictly better
  • Confusing preemption with priority scheduling as if they were the same thing
  • Forgetting that non-preemptive scheduling can starve interactive tasks
  • Not naming any real algorithms as examples

Best Answer (HR Friendly)

Preemptive scheduling means the operating system can pause a running task at any moment to hand the CPU to something more urgent. Non-preemptive scheduling means a task keeps the CPU until it is done or waiting on something, which is simpler but less responsive.

Code Example

Simplified round robin (preemptive) vs FCFS (non-preemptive)
#include <stdio.h>

typedef struct { int id; int burst; int remaining; } Task;

/* Non-preemptive: run each task fully in arrival order. */
void fcfs(Task tasks[], int n) {
    for (int i = 0; i < n; i++) {
        printf("Run task %d for %d units (no interruption)\n",
               tasks[i].id, tasks[i].burst);
    }
}

/* Preemptive: give each ready task a fixed time slice, cycling
   back around until all tasks finish. */
void round_robin(Task tasks[], int n, int quantum) {
    int done = 0;
    while (done < n) {
        for (int i = 0; i < n; i++) {
            if (tasks[i].remaining <= 0) continue;
            int slice = tasks[i].remaining < quantum ? tasks[i].remaining : quantum;
            printf("Preempt: run task %d for %d units\n", tasks[i].id, slice);
            tasks[i].remaining -= slice;
            if (tasks[i].remaining == 0) done++;
        }
    }
}

Follow-up Questions

  • What is a context switch and why does preemption increase its frequency?
  • How does priority inversion relate to preemptive scheduling?
  • What is the difference between round robin and multilevel feedback queue scheduling?
  • Why can non-preemptive scheduling starve short jobs behind a long one?

MCQ Practice

1. Which scheduling algorithm is preemptive?

Round robin uses a timer to forcibly switch tasks after each time quantum, making it preemptive.

2. A key risk of non-preemptive scheduling is?

Without forced interruption, a long-running process can hold the CPU and starve everything waiting behind it.

3. What mechanism most commonly triggers preemption?

A periodic timer interrupt gives the OS scheduler a chance to forcibly reassign the CPU.

Flash Cards

Preemptive scheduling in one line?The OS can forcibly suspend a running task to run another.

Non-preemptive scheduling in one line?A task keeps the CPU until it finishes or blocks voluntarily.

Give one preemptive algorithm.Round robin (or preemptive priority scheduling).

Give one non-preemptive algorithm.First-Come-First-Served (or non-preemptive SJF).

1 / 4

Continue Learning