Pre-emptive Priority Scheduling Algorithm | Operating System - M02 P08

Pre-emptive Priority Scheduling Algorithm | Operating System - M02 P08

This is a multipart blog article series, and in this series I am going to explain you the concepts of operating system. This article series is divided into multiple modules and this is the second module which consists of 11 articles.

In this article we will see about priority scheduling algorithm with pre-emptive in an operating system with the help of a question.

Pre-emptive priority scheduling algorithm

  • The criterion of this scheduling algorithm is priority, which means the process with height priority will be executed first.
  • The mode of pre-emptive priority scheduling algorithm is as the name suggest pre-emptive.

Let us understand about pre-emptive priority scheduling algorithm with an example. We have to complete this table by solving this question by using gantt chart.

Process No.PriorityArrival timeBurst timeCompletion timeTurnaround timeWaiting time
P11005
P22014
P33022
P44041

Higher the number higher the priority

Before solving this question you need to keep few point in mind.

  • We have to check that what does the priority means that is (higher the number higher the priority) or (higher the number lower the priority.)
  • In case if the priority of two processes is same then check the arrival time and treat as (first come first serve), generally in question how to deal with such conflicts is mentioned but if nothing is mentioned then you can easily follow (FCFS).
  • If arrival time is also same then in that case execute according to the ID of the process.

Untitled Diagram.png

  • The process P1 arrives at time unit 0 so it starts executing.
  • We execute P1 for 1 time unit only because at time unit 1 another process with higher priority arrives in the ready queue, so P1 will get preempted.

Untitled Diagram (1).png

  • P2’s execution will start as it has higher priority than P1.
  • P2 will get executed for 1 unit of time because at time unit 2 another process with higher priority arrives in the ready queue, P2 will get preempted.

Untitled Diagram (2).png

  • P3 will start executing as it has higher priority than P2 and P1.
  • P3 will get executed for 2 unit of time and then get terminated as its burst time is 2.

Untitled Diagram (3).png

  • P4 will execute for 1 unit of time and then get terminated as its burst time is only 1.
  • Now the process from the ready queue will again come in the running state.

Untitled Diagram (4).png

  • P2’s execution will start again as it is the process with height priority.
  • It will get executed 3 unit of time and then get terminated as it got complete.

Untitled Diagram (5).png

  • P1 is the only process in the ready queue all the other processes are terminated, so it will execute completely.

All the process got completely executed. Now we will complete the table, but for it you need to know some formulas.

  • Completion time: The time at which process completes its execution.
  • Turnaround time = Completion time – arrival time.
  • Waiting time = Turnaround time – burst time.
Process No.PriorityArrival timeBurst timeCompletion timeTurnaround timeWaiting time
P1100512127
P22014873
P33022420
P44041510

So, this was all about Pre-emptive priority scheduling algorithm. Hope you like it and learned something new from it.

If you have any doubt, question, queries related to this topic or just want to share something with me, then please feel free to contact me.

📱 Contact Me

Twitter, LinkedIn, Telegram, Instagram,

📧 Write a mail

rahulmishra102000@gmail.com

GitHub, HackerRank