Fixed-priority pre-emptive scheduling

Prerequisite – CPU Scheduling in Operating Systems
Fixed priority pre-emptive scheduling algorithm is mostly used in real time systems.
In this scheduling algorithm the processor make sure that the highest priority task is to be performed first ignoring the other task to be executed.

The process having highest priority is served first.

Decision Mode:
Pre-emptive: When a process arrives its priority is compared with the current process’s priority.If the new job have higher priority then the current process, the current process is suspended and new process is started.

Implementation:
Sorted FIFO queue is used for this strategy. As the new process is identified it is placed in the queue according to it’s priority.Hence the process having higher priority is considered first as it is placed at higher position.

Example:
Let us take the following example having 4 set of processes along with its arrival time and time taken to complete the process.Also the priority of all the process are mentioned.Consider all time values in millisecond and small value of priority means higher priority of process.



Process Arrival Time(T0) Time Required for Completion(T`) Priority
P0 0 10 5
P1 1 6 4
P2 3 2 2
P3 5 4 0

Gantt chart:

Initially only P0 is present and it is allowed to run.But when P1 comes, it has higher priority.So, P0 is pre-empted and P1 is allowed to run.This process repeated till all processes complete their execution.

Statistic :

Process Arrival Time(T0) Completion time(T`) Finish Time(T1) TurnAround time(TAT=T1-T0) Waiting time(TAT-T`)
P0 0 10 22 22 12
P1 1 6 13 12 6
P2 3 2 5 2 0
P3 5 4 9 4 0

Average Turnaround time:

= (22+12+2+4) / 4    
= 40 / 4
= 10 ms 

Average Waiting time:

= (12+6+0+0) / 4    
= 18 / 4
= 4.5 ms 

Advantages:
Priority is considered.Critical process can get even better response.

Disadvantage:
Starvation is possible for low priority process.It can be overcome by using technique called “Aging“. Aging gradually increases the priority of the process that wait in the system for long time. Context switch overhead is there.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.