Priority Based Scheduling Algorithm

Priority Based Scheduling Algorithm

Priority Based Scheduling Algorithm

It is a Priority based scheduling algorithm of an operating system.

  • In the Priority based scheduling algorithm, Priority is assigned for each process.
  • It is an integer number.
  • It can be Preemptive or Non-Preemptive.
  • A process with the highest priority is executed first and so on.
  • Same Priority Can be broken with FCFS Algorithm.
  • No Importance of Arrival Time and Burst Time.
Process Arrival Time Burst Time Priority
P0 0 5 1
P1 1 3 2
P2 2 8 1
P3 3 6 3

Priority Based Scheduling Algorithm Preemptive

  • Only one process is arriving at 0 time P0. so, we have to do the execution of process P0 for 1 unit time.
  • After that First process is getting the executes the process p1 has arrived and the priority of P1 is higher than P0. So, process P1 getting the execution.
  • After that, process P2 arrives. but the priority of process P2 is less than the P1. so P1 again gets an execution.
  • Similarly, All the processes execute likewise.

Gantt Chart

priority preemptive

Process Arrival Time Burst Time Priority Completion Time Turn around Time Waiting Time
P0 0 5 1 14 14 9
P1 1 3 2 10 9 6
P2 2 8 1 22 10 2
P3 3 6 3 9 6 0

Priority Based Scheduling Algorithm Non-Preemptive:

  • Only one process is arriving at 0 time P0.so, we have to do execution of process P0.
  • After the completion of process P0. All the processes have arrived.
  • but the priority of Process is P3. so that, process P3 gets the execution first.
  • Likewise, all the processes get the execution.

Gantt Chart

priority non preemptive

Process Arrival Time Burst Time Priority Completion Time Turn around Time Waiting Time
P0 0 5 1 5 5 0
P1 1 3 2 14 13 10
P2 2 8 1 12 20 12
P3 3 6 3 11 8 2

Problem

  • Starvation – low priority processes may never execute.
  • In Priority-Based Scheduling Algorithm the chances of indefinite blocking and starvation.
  • When CPU runs on other process It blocked Priority Scheduling when it is ready to run.

Solution

  • Aging – increasing the priority of those process that has been waiting long because of low priority after some specified amount of time.

Also Check –> Round Robbin Scheduling Algorithm. 

Implementation of Priority algorithm in C language

#include<stdio.h>

int main()
{
int p[30],pr[30],key,loc,bt[30],temp,max,wt[30],ta[30],sum=0,i,j,n;
wt[0]=0;
printf("enter the number of processes=");
scanf("%d",&n);
printf("enter the burst time for each process");
for(i=0;i<n;i++)
{
p[i]=i+1;
printf("\np%d=",i+1);
scanf("%d",&bt[i]);
printf("priority of p%d=",i+1);
scanf("%d",&pr[i]);
}
for(i=0;i<n;i++)
{ max=i;
for(j=i+1;j<n;j++)
{
if(pr[j] <pr[max])
max=j;
}
temp=pr[max];
pr[max]=pr[i];
pr[i]=temp;
temp=bt[max];
bt[max]=bt[i];
bt[i]=temp;
temp=p[max];
p[max]=p[i];
p[i]=temp;
}
for(i=0;i<n;i++)
{ wt[i+1]=bt[i]+wt[i];
ta[i]=bt[i]+wt[i];
sum+=ta[i];
}
for(i=0;i<n;i++)
{
printf("\n waiting time for p[%d]=%d",p[i],wt[i]);
printf("\t turn around time for p[%d]=%d",p[i],ta[i]);
}
printf("\n\n average turn around=%d",sum/n);
return 1;
}

Aging Technique with Priority based scheduling algorithm

This technique generally used to prevent the starvation of any process. If we increasing priority that considers low-priority based on the waiting time. (Aging technique)

For example if we decide the aging factor 0.4 and we decide the priority 30 (whichever is low priority) It added into the queue, the next day the priority increase to the 29.6 and so on.

 

If you have any comments or query then don’t hesitate to ask us. Just comment below or contact us via social media pages.

To learn more concept about Priority go to 
https://www.geeksforgeeks.org/program-priority-scheduling-set-1/

For Android projects goto the ANDROID

Stay Connect with our app

https://play.google.com/store/apps/details?id=com.edu.easyengineer

For Assignment Questions and Explanation of a theory topic visit

Eupload

Note for Visitors

Here easy engineering provides materials related to exams online by this blog. The main aim of the blog is to provide materials that are not able to buy books from the market. If you like our service then please kindly share it with your university students and other students who are not able to buy books.

Warning

this copy of books is not for sale.

Declaimers

Easyengneering.in provides material by collecting from different websites, so we are not the original publishers of books or materials. we are publishers of contents or posts which can help to your carrier. for any quarries contact us on easyengineeringkp@gmail.com. I hope you like this education blog and we are ready to help those students who really deserve to learn but they can’t afford the money.

Join our telegram group for daily updates of websites 

t.me/easyengineeringkp

Join our Facebook page for more details and daily updates

https://www.facebook.com/easyengineeringkp

About easyengineering 38 Articles
Easyengineering.in provides you to all subject and exam related materials online like GPSC, UPSC, IES, GATE, etc. As well as we provide daily job notification, some life-related books and other online courses which are useful too in your study.

2 Comments

  1. I’m really enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire
    out a developer to create your theme? Outstanding work!

Leave a Reply

Your email address will not be published.


*