Operating Systems use various scheduling algorithms to schedule the execution of different processes on the CPU, and
The priority scheduling algorithm is further divided into two following types:
Preemptive priority scheduling
Non-preemptive priority scheduling
Note: Learn more about preemptive priority scheduling, click here.
In this answer, we'll discuss the non-preemptive priority scheduling algorithm.
In non-preemptive priority scheduling, the CPU gets allocated to a specific process based on the priority numbers assigned. After the CPU allocation, it will only be released by context switching or terminating the process. This scheduling is widely used for various hardware platforms because it doesn't require any special hardware (timer etc.) like preemptive scheduling.
Note: Process with less priority number will get CPU allocation first.
Process priority numbers are of two types:
Static priority: The priority number is static if the assigned priority number doesn't change itself throughout the process.
Dynamic priority: The priority number is dynamic if the assigned priority number change itself throughout the process.
Suppose we've got seven following processes with their priority number and arrival time given; let's schedule them using a non-preemptive priority scheduling:
Process | Arrival Time | Burst Time | Priority No |
P1 | 0 | 3 | 2 |
P2 | 2 | 5 | 6 |
P3 | 1 | 4 | 3 |
P4 | 4 | 2 | 5 |
P5 | 6 | 9 | 7 |
P6 | 5 | 4 | 4 |
P7 | 7 | 10 | 10 |
Let's handle this process scheduling using non-preemptive priority scheduling. Here’s a step-by-step execution:
P1 arrives at the time
While the execution of P1, two new processes P2 and P3 arrived, the priority of P3 is 3 hence it will get CPU allocation over P3 and P2.
While the execution of P3, all other processes get ready in the
When P6 gets executed, P4 has the lowest priority among all remaining processes, it will get executed till complete execution.
The same process (step1 - step4) continue until the completion of all processes execution, according to their priorities number. If two processes have the same priority numbers, then the process with a smaller arrival time will get executed first.
Have a look at the Gantt chart of our example:
The advantages of non-preemptive priority scheduling are the following:
It's easy to implement and use this scheduling.
Processes get executed based on their priority, so processes with higher priority get executed first, which saves time.
It's suitable for applications with resource requirements and fluctuating time.
The disadvantages of non-preemptive priority scheduling are the following:
It has computing overhead, when the system crashes, almost all the processes with low priorities get lost.
Larger processes take a lot of time, then the lower priority processes may starve and get postponed.
Based on priority, it may leave some low-priority processes for a longer time.
Free Resources