What is Priority Scheduling in an Operating System? (A Simple Guide)
Ever feel like your computer's CPU has a "VIP list"? You're running a critical system update, and suddenly your mouse-click (a very small task) gets an immediate response, cutting in line ahead of the huge update. That's the magic of priority scheduling.
In an operating system, Priority Scheduling is an algorithm that schedules processes based on their assigned priority level. Unlike "first-come, first-served," where everyone waits in the same line, this method gives a "fast pass" to more important tasks.
A simple rule governs this:
- The scheduler will always pick the process with the highest priority from the ready queue.
- If multiple processes have the same priority, they are typically handled in First-Come, First-Served (FCFS) order.
Note: Priorities are just numbers. By convention, we'll assume that a lower number means a higher priority (e.g., Priority 1 is more important than Priority 4).
⚙️ 2 Flavors: Preemptive vs. Non-Preemptive
This is the most important concept to understand. The algorithm behaves completely differently depending on which "flavor" it is.
1. Non-Preemptive Priority Scheduling:
This is the "polite" version. When a new, high-priority process arrives, it's placed at the front of the ready queue. However, the scheduler waits for the currently running process to finish its CPU burst completely before switching. It won't interrupt a task that's already in progress.
2. Preemptive Priority Scheduling:
This is the "ruthless" version. When a new, high-priority process arrives, the scheduler immediately compares its priority to the priority of the currently running process. If the new process is more important, the OS stops (preempts) the current task, puts it back in the ready queue, and runs the new high-priority one.
⚙️ Priority Scheduling in Action: An Example
Let's see how the same set of processes runs on both types. You can try this yourself in the calculator below!
Our Process Data: (Remember: Lower number = Higher Priority)
| Process | Arrival Time (AT) | Burst Time (ET) | Priority |
|---|---|---|---|
| P0 | 0 | 5 | 2 |
| P1 | 1 | 3 | 1 (Highest) |
| P2 | 2 | 8 | 3 |
| P3 | 3 | 6 | 2 |
Example 1: Non-Preemptive Priority Scheduling
In this version, we cannot interrupt a running process.
- Time 0: P0 arrives and starts.
- Time 1-3: P1, P2, and P3 arrive and are added to the ready queue, sorted by priority:
[P1, P3, P2]. - Time 5: P0 finishes. The scheduler picks P1 (highest priority).
- Time 8: P1 finishes. The scheduler picks P3 (next highest priority).
- Time 14: P3 finishes. The scheduler picks P2.
- Time 22: P2 finishes.
Example 2: Preemptive Priority Scheduling
Here, we can interrupt a running process.
- Time 0: P0 (Prio 2) arrives and starts.
- Time 1: P1 (Prio 1) arrives. P1 has a higher priority than P0, so P0 is preempted. P1 starts.
- Time 4: P1 finishes. The scheduler checks the ready queue:
[P0(Prio 2), P2(Prio 3), P3(Prio 2)]. P0 and P3 are tied. P0 wins the FCFS tie-break and resumes. - Time 9: P0 finishes. The scheduler picks P3 (Prio 2).
- Time 15: P3 finishes. The scheduler picks P2.
- Time 23: P2 finishes.
⚠️ The Big Problem: Starvation
There's a massive potential problem in any priority-based system: Indefinite Blocking, or Starvation. This happens when a low-priority process might never get a chance to run because new, higher-priority processes keep arriving.
💡 The Solution: Aging
The most common solution to starvation is Aging. This is a technique where the OS gradually increases the priority of processes that have been waiting in the ready queue for a long time, ensuring they eventually get to run.
Try It Yourself! Dynamic Calculator
Enter your own processes and toggle between modes to see the results change.
Process Input
| Process | AT | ET | Priority | Remove |
|---|
Settings
Algorithm Mode:
Test Your Knowledge!
1. What is the term for a low-priority process that is indefinitely stuck in the ready queue and never gets to run?
2. A new high-priority process arrives, but the CPU continues to run the current low-priority process until it finishes. This is an example of:
3. What is the most common solution to starvation?

0 Comments