PREEMPTIVE PRIORITY
In Preemptive Priority Scheduling, at the time of arrival of a process in the ready queue,
its Priority is compared with the priority of the other processes present in the ready queue as well as
with the one which is being executed by the CPU at that point of time.
The One with the highest priority among all the available processes will be given the CPU next.
The difference between preemptive priority scheduling and non preemptive priority scheduling is that,
in the preemptive priority scheduling, the job which is being executed can be stopped at the arrival of a higher priority job.
Once all the jobs get available in the ready queue, the algorithm will behave as non-preemptive priority scheduling,
which means the job scheduled will run till the completion and no preemption will be done.
Algorithm
Let us consider five process having ID P1, P2, P3, P4, P5 respectively.
It's arrival time is 0, 1, 2, 3, 4 respectively.
It's burst time is 8, 1, 3, 2, 6 respectively.
And it's priority is 3, 1, 2, 3, 4 respectively.
Now 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