Operating System - Priority Scheduling Algorithm
What is Priority Scheduling
Priority Scheduling is a non-preemptive or preemptive CPU scheduling algorithm where each process is assigned a priority, and the CPU is allocated to the process with the highest priority.
Lower number = higher priority (unless specified otherwise)
-
Can be Preemptive or Non-Preemptive
-
Priority is either assigned (static) or calculated dynamically.
-
Starvation is possible if low-priority processes wait too long.
-
Aging technique can be used to prevent starvation by increasing priority over time.
Example (Non-Preemptive Priority Scheduling)
Given:
Process | Arrival Time | Burst Time | Priority |
---|---|---|---|
P1 | 0 | 10 | 3 |
P2 | 2 | 1 | 1 |
P3 | 3 | 2 | 4 |
P4 | 5 | 1 | 2 |
1. At time 0, only P1 has arrived → run P1
2. At time 10, P2, P3, and P4 have arrived.
-
Highest priority among them is P2 (priority 1) → run P2