- Priority scheduling assigns each process a priority, and the CPU is allocated to the highest-priority process.
- Equal-priority processes are scheduled in FCFS order. SJF is a special case where priority is the inverse of next CPU burst.
Example
Consider the following set of processes with their burst times and priorities:
Process | Burst Time | Priority |
---|---|---|
P1 | 10 | 3 |
P2 | 1 | 1 |
P3 | 2 | 4 |
P4 | 1 | 5 |
P5 | 5 | 2 |
Using priority scheduling, we would schedule these processes according to the following Gantt chart:
![](https://bscbcanotes.wordpress.com/wp-content/uploads/2024/05/image-158.png?w=492)
The average waiting time is calculated to be 8.2 milliseconds.
- Priorities can be defined internally or externally.
- Internally defined priorities use measurable quantities like time limits, memory requirements, or ratios of I/O burst to CPU burst.
- External priorities are set by criteria outside the operating system, such as the importance of the process or political factors.
- Priority scheduling can be preemptive or nonpreemptive.
- In preemptive priority scheduling, a newly arrived process with a higher priority can preempt the CPU from the currently running process.
- In nonpreemptive priority scheduling, the new process is simply placed at the head of the ready queue.
A major issue with priority scheduling algorithms is indefinite blocking or starvation, where low-priority processes wait indefinitely for CPU access. Aging is a solution to this problem, involving gradually increasing the priority of processes that wait in the system for a long time. This ensures that even low-priority processes eventually get CPU access.
Priority scheduling offers flexibility in process execution by allowing processes to be prioritized based on various criteria. However, care must be taken to prevent indefinite blocking of low-priority processes through techniques like aging.