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

What is Priority Scheduling?

Learn priority scheduling — preemptive vs non-preemptive, starvation, and aging as the fix — with OS interview questions answered.

mediumQ28 of 224 in Operating Systems Est. time: 6 minsLast updated:
Open Code Lab

Expected Interview Answer

Priority scheduling dispatches the ready process with the highest priority value next, rather than by arrival order or burst time, and can be implemented as either preemptive (a higher-priority arrival interrupts the running process) or non-preemptive (the running process finishes its burst first).

Each process is assigned a priority number — assigned statically at creation or computed dynamically from factors like memory needs, I/O behavior, or user importance — and the scheduler always selects the highest-priority ready process. In the preemptive variant, if a process with higher priority than the currently running one becomes ready, the CPU is immediately reassigned; in the non-preemptive variant, the newly arrived higher-priority process must wait until the current burst finishes. The core weakness of priority scheduling is starvation: a low-priority process can wait indefinitely if a continuous stream of higher-priority processes keeps arriving, since nothing forces the scheduler to ever consider it. The standard fix is aging, where a process’s priority is gradually increased the longer it waits in the ready queue, eventually guaranteeing it becomes the highest priority and runs — without aging, priority scheduling offers no fairness guarantee at all.

  • Lets important or time-critical tasks be serviced ahead of routine work
  • Flexible — priority can be static or dynamically computed
  • Foundation for real-time and multilevel scheduling designs
  • Aging solves starvation while preserving priority intent

AI Mentor Explanation

Priority scheduling is like a team management always sending the in-form star batter to the crease first whenever a wicket falls, ahead of lower-order players regardless of who has been waiting longer. If star batters keep arriving one after another, a reserve batter waiting on the bench could sit out the entire match. The fix teams use is gradually promoting a benched player’s standing the longer they wait, guaranteeing they eventually get a turn — exactly like aging in priority scheduling.

Step-by-Step Explanation

  1. Step 1

    Assign priority

    Each process is given a priority value, either fixed at creation or computed dynamically from workload characteristics.

  2. Step 2

    Select highest priority

    The scheduler scans the ready queue and selects the process with the highest priority value.

  3. Step 3

    Preempt if applicable

    In the preemptive variant, a newly arrived higher-priority process immediately interrupts the currently running one.

  4. Step 4

    Apply aging

    Waiting processes have their priority gradually raised over time so no process is starved indefinitely.

What Interviewer Expects

  • Clear description of both preemptive and non-preemptive priority scheduling
  • Recognition that priority scheduling can starve low-priority processes
  • Correct explanation of aging as the fix for starvation
  • Awareness that priority can be static or dynamically computed

Common Mistakes

  • Not mentioning starvation as the core weakness of priority scheduling
  • Forgetting that aging is the standard mitigation
  • Confusing priority scheduling with multilevel queue scheduling
  • Assuming priority scheduling is always preemptive (it can be either)

Best Answer (HR Friendly)

Priority scheduling always runs whichever waiting task has the highest priority next, so urgent or important work gets serviced first. The risk is that a low-priority task can be stuck waiting forever if higher-priority tasks keep showing up, so systems usually gradually raise a waiting task’s priority the longer it sits — that is called aging, and it guarantees everything eventually gets its turn.

Code Example

Priority scheduling with aging to prevent starvation
struct process {
    int pid;
    int priority;      /* lower number = higher priority */
    int waiting_time;
    int completed;
};

#define AGE_STEP 1
#define AGE_INTERVAL 5

void apply_aging(struct process procs[], int n) {
    for (int i = 0; i < n; i++) {
        if (!procs[i].completed && procs[i].waiting_time % AGE_INTERVAL == 0) {
            if (procs[i].priority > 0) procs[i].priority -= AGE_STEP;
        }
    }
}

int pick_highest_priority(struct process procs[], int n) {
    int idx = -1, best = INT_MAX;
    for (int i = 0; i < n; i++) {
        if (!procs[i].completed && procs[i].priority < best) {
            best = procs[i].priority;
            idx = i;
        }
    }
    return idx;
}

Follow-up Questions

  • What is starvation in priority scheduling and how does aging prevent it?
  • How does priority scheduling differ when preemptive vs non-preemptive?
  • How might process priority be computed dynamically at runtime?
  • How does priority scheduling relate to priority inversion in real-time systems?

MCQ Practice

1. Priority scheduling selects the next process based on?

Priority scheduling always dispatches the ready process with the highest priority, regardless of arrival order or burst time.

2. What technique prevents starvation in priority scheduling?

Aging incrementally increases a waiting process’s priority over time, ensuring it eventually becomes the highest priority and runs.

3. In preemptive priority scheduling, what happens when a higher-priority process arrives?

In the preemptive variant, the CPU is immediately reassigned to the newly arrived process if its priority exceeds the running process’s.

Flash Cards

What is priority scheduling?A policy that dispatches the ready process with the highest priority value next.

What is priority scheduling’s main risk?Starvation of low-priority processes if higher-priority ones keep arriving.

How is starvation fixed in priority scheduling?Aging — gradually raising a waiting process’s priority over time.

Can priority scheduling be non-preemptive?Yes — the running process can either be preempted or allowed to finish its burst first.

1 / 4

Continue Learning