Open In App

Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms

Last Updated : 01 Jun, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – CPU Scheduling 
Priority Scheduling : 
In priority scheduling, each process has a priority which is an integer value assigned to it. 
The smallest integer is considered as the highest priority and the largest integer is considered as the lowest priority. The process with the highest priority gets the CPU first. 

In rare systems, the largest number might be treated as the highest priority also so it all depends on the implementation. 

If priorities are internally defined then some measurable quantities such as time limits, memory requirements, the number of open files and the ratio of average I/O burst to average CPU burst are used to compute priorities. 
External priorities are assigned on the basis of factors such as the importance of process, the type and amount of funds been paid for computer use, the department sponsoring of the work, etc. 

Preemptive and non-preemptive SJF is a priority scheduling where priority is the shortest execution time of job. In this algorithm, low priority processes may never execute. This is called starvation. 

The solution to this starvation problem is aging. In aging, as time progresses, increase the priority of the process so that the lowest priority process gets converted to the highest priority gradually. 

 

  1. Priority Preemptive Scheduling : 
    Sometimes it is important to execute higher priority tasks immediately even when a task is currently being executed. For example, when a phone call is received, the CPU is immediately assigned to this task even if some other application is currently being used. This is because the incoming phone call has a higher priority than other tasks. This is a perfect example of priority preemptive scheduling. If a task with higher priority than the current task being executed arrives then the control of the CPU is taken from the current task and given to the higher priority task. 

     

  2. Priority Non-Preemptive Scheduling : 
    Unlike priority preemptive scheduling, even if a task with higher priority does arrive, it has to wait for the current task to release the CPU before it can be executed. It is often used in various hardware procedures such as timers, etc. 

Note: 
If all the processes arrive at the same time then priority preemptive scheduling and priority non-preemptive scheduling work in the same manner. 

Now let’s do a comparative study of preemptive priority scheduling and non-preemptive priority scheduling. 

 

PRIORITY PREEMPTIVE SCHEDULING PRIORITY NON PREEMPTIVE SCHEDULING
If a process with higher priority than the process currently being executed arrives, the CPU is preemeted and given to the higher priority process. Once resources are allocated to a process, the process holds it till it completes its burst time even if a process with higher priority is added to the queue.
Preemptive scheduling is more flexible. Non-preemptive scheduling is rigid.
The waiting time for the process having the highest priority will always be zero. The waiting time for the process having the highest priority may not be zero.
It is more expensive and difficult to implement. Also a lot of time is wasted in switching. It is cheaper to implement and faster as less switching is required.
It is useful in applications where high priority processes cannot be kept waiting. It can be used in various hardware applications where waiting will not cause any serious issues.

Example: 

 

Process Arrival Time Burst Time Priority
P1 0 8 3
P2 1 1 1
P3 2 3 2
P4 3 2 3
P5 4 6 4

Let’s try and solve this problem using both algorithms to do a comparative study. 

1. Priority Non-preemptive scheduling : 
The Gantt chart will look like: 

 

Average waiting time (AWT), 

= ((0-0) + (8-1) + (9-2) + (12-3) + (14-4)) / 5 
= 33 / 5 
= 6.6 

Average turnaround time (TAT),  

= ((8-0) + (9-1) + (12-2) + (14-3) + (20-4)) / 4 
= 53 / 5 
= 10.6 

2. Priority Preemptive scheduling : 
The Gantt chart will look like: 

 

Average waiting time (AWT), 

= ((5-1) + (1-1) + (2-2) + (12-3) + (14-4)) / 5 
= 23/5 
= 4.6 

Average turnaround time (TAT), 

= ((12-0) + (2-1) + (5-2) + (14-3) + (20-4)) / 5 
= 43 / 5 
= 8.6 

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads