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. | Priority | Arrival time | Burst time | Completion time | Turnaround time | Waiting time |
|---|---|---|---|---|---|---|
| P1 | 10 | 0 | 5 | |||
| P2 | 20 | 1 | 4 | |||
| P3 | 30 | 2 | 2 | |||
| P4 | 40 | 4 | 1 |
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.
- The process
P1arrives at time unit0so it starts executing. - We execute
P1for1time unit only because at time unit1another process with higher priority arrives in the ready queue, soP1will get preempted.
- P2’s execution will start as it has higher priority than
P1. -
P2will get executed for1unit of time because at time unit2another process with higher priority arrives in the ready queue,P2will get preempted.
-
P3will start executing as it has higher priority thanP2andP1. -
P3will get executed for2unit of time and then get terminated as its burst time is2.
-
P4will execute for1unit of time and then get terminated as its burst time is only1. - Now the process from the ready queue will again come in the running state.
- P2’s execution will start again as it is the process with height priority.
- It will get executed
3unit of time and then get terminated as it got complete.
-
P1is 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. | Priority | Arrival time | Burst time | Completion time | Turnaround time | Waiting time |
|---|---|---|---|---|---|---|
| P1 | 10 | 0 | 5 | 12 | 12 | 7 |
| P2 | 20 | 1 | 4 | 8 | 7 | 3 |
| P3 | 30 | 2 | 2 | 4 | 2 | 0 |
| P4 | 40 | 4 | 1 | 5 | 1 | 0 |
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,






Top comments (0)