Preemptive Priority Scheduling Algorithm

For Complete YouTube Video: Click Here

In this class, we will try to understand the Preemptive Priority Scheduling Algorithm.

We have already discussed the non-preemptive priority scheduling algorithm concepts in our previous classes.

Preemptive Priority Scheduling Algorithm

In the preemptive priority scheduling algorithm, the processes will get preempted if a high-priority process arrives.

For example, if a process is executing on the CPU.

And while it is getting executed, if another process with high priority arrives in the ready pool, then the process in the running state will be switched to the running and gives room for the high-priority process that has arrived.

For a better understanding, consider the example below.

At the 0th arrival time, we have only process P1, and the process P1 will get executed.

While process P1 is getting executed after one unit in time, P2 has arrived.

Now, we have to check the priority of the process. If the newly arrived process has the highest priority, then that process will get executed. If not, process P1 will continue its execution.

Here we will assume that the process with a low priority number will have the highest priority and the process with a high priority number will have the lowest priority.

Based on the assumption, process P2 has the highest priority.

So process P2 will get executed.

At arrival time three, process P3 has arrived. Now we have to check for the priority of all the processes in the pool.

By this point, P1 has completed one unit of burst time, and P2 has completed two units of burst time.

Among P1, P2, and P3, P2 has the highest priority, and P2 will get executed.

At arrival time four, no process has arrived, so P2 will continue its execution and completes its execution at the fifth unit in time.

At the fifth unit, process P5 has arrived, and all the processes arrived in the ready pool.

Comparing all the priorities, P1 has the highest priority and will complete its execution.

Next, P3, P4, and P5 will get executed based on the priorities of the processes.

Using the Gantt Chart, we will construct the Completion Time, Turn Around Time, and Waiting Time as shown below.