What is Preemptive Priority CPU Scheduling?
Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method of CPU scheduling algorithm that works based on the priority of a process. In this algorithm, the scheduler schedules the tasks to work as per the priority, which means that a higher priority process should be executed first. In case of any conflict, i.e., when there is more than one process with equal priorities, then the pre-emptive priority CPU scheduling algorithm works on the basis of FCFS (First Come First Serve) algorithm.
Advantages of Preemptive Priority CPU Scheduling
- Efficient utilization of resources: Preemptive priority scheduling ensures that the most important tasks are executed first, which helps in efficient utilization of resources.
- Faster response time: Higher priority tasks are given priority over lower priority tasks, which results in faster response times for important tasks.
- Guaranteed service: Preemptive priority scheduling ensures that the high-priority tasks are always executed first, which provides guaranteed service for critical applications.
Disadvantages of Preemptive Priority Scheduling
- Starvation: Preemptive priority scheduling can lead to starvation of lower priority tasks if higher priority tasks keep arriving. This can lead to poor performance of the system.
- Priority inversion: Preemptive priority scheduling can also lead to priority inversion, where a lower priority task holds a resource required by a higher priority task, resulting in the higher priority task being blocked.
- Complexity: Preemptive priority scheduling is a complex algorithm that requires careful implementation to ensure that the system operates as intended. This can increase the complexity of the operating system and make it more difficult to maintain.
Algorithm steps
- Step-1: Select the first process whose arrival time will be 0, we need to select that process because that process is only executing at time t=0.
- Step-2: Check the priority of the next available process. Here we need to check for 3 conditions.
if priority(current_process) > priority(prior_process) :- then execute the current process.
if priority(current_process) < priority(prior_process) :- then execute the prior process.
if priority(current_process) = priority(prior_process) :- then execute the process which arrives first i.e., arrival time should be first. - Step-3: Repeat Step-2 until it reaches the final process.
- Step-4: When it reaches the final process, choose the process which is having the highest priority & execute it. Repeat the same step until all processes complete their execution.