Priority (Preemptive) Algorithm

This is the Preemptive version of Priority scheduling. In this type of scheduling the processes which are present in ready queue are compared and the process with highest priority is selected for execution.The difference between non-Preemptive Priority Scheduling and Preemptive Priority Scheduling is that in non-preemptive if a process comes inside CPU then it can't be preempted and it will execute completely. However, in case of Preemptive Priority Scheduling a process which is executing inside CPU can be preempted if a higher priority process comes in the ready queue.

Characteristics

Advantages

Disadvantages

Example

Process Priority Arrival Time Burst Time
P1 10(L) 0 5
P2 20 1 4
P3 30 2 2
P4 40(H) 4 10

Working

Gantt Chart

P1 P2 P3 P4 P2 P1
0 - 1 1 - 2 2 - 4 4 - 5 5 - 8 8 - 12

Final Table

Process Priority Arrival Time Burst Time Completion Time Turn Around Time Waiting Time Response Time
P1 10(L) 0 5 12 12 7 0
P2 20 1 4 8 7 3 0
P3 30 2 2 4 2 0 0
P4 40(H) 4 1 5 1 0 0