Priority Scheduling Implementation
Do you like this story?
/*PROGRAM TO IMPLEMENT THE CONCEPTS OF PRIORITY-SCHEDULING*/
#include
void main()
{
int bt[3],at[3],pr[3];
int wt[3],ft[3],tat[3];
int n,i,sum=0,j,x,z,t;
float awt;
char p[3][9],y[9];
clrscr();
printf("\nEnter the process,burst-time and priority:");
for(i=0;i<3;i++)
scanf("%s%d%d",p[i],&bt[i],&pr[i]);
printf("\nEnter the arrival-time:");
for(i=0;i<3;i++)
scanf("%d",&at[i]);
printf("\nThe actual order:");
printf("\nProcess Burst-time Priority\n");
for(i=0;i<3;i++)
printf("\n%s%d%d",p[i],bt[i],pr[i]);
for(i=0;i<3;i++)
for(j=i+1;j<3;j++)
{
if(pr[i]>pr[j])
{
x=pr[j];
pr[j]=pr[i];
pr[i]=x;
strcpy(y,p[j]);
strcpy(p[j],p[i]);
strcpy(p[i],y);
z=bt[j];
bt[j]=bt[i];
bt[i]=z;
t=at[j];
at[j]=at[i];
at[i]=t;
}
}
wt[0]=0;
for(i=1;i<3;i++)
wt[i]=wt[i-1]+bt[i-1];
ft[0]=bt[0];
for(i=1;i<3;i++)
ft[i]=ft[i-1]+bt[i];
for(i=0;i<3;i++)
tat[i]=ft[i]-at[i];
for(i=0;i<3;i++)
sum=sum+wt[i];
awt=sum/3.0;
printf("\nPRIORITY SCHEDULING:\n");
printf("\nThe order they are executed:\n");
printf("\nProcess Priority Burst-time Arrival-time
Waiting-time Finish-time Turnaround-time");
for(i=0;i<3;i++)
printf("\n\n%d%s\t%d\t%d\t\t%d\t\t%d\t\t%d\t\t%d",
i+1,p[i],pr[i],bt[i],at[i],wt[i],ft[i],tat[i]);
printf("\n\nAverage waiting time:%f",awt);
}
/*OUTPUT FOR PRIORITY SCHEDULING*/
INPUT:
Enter process,burst-time and priority:
p1 10 8
p2 20 3
p3 30 5
Enter the arrival-time:
1
2
3
OUTPUT:
The actual order:
Process Burst-time Priority
p1 10 8
p2 20 3
p3 30 5
PRIORITY SCHEDULING
The order they are executed:
Process Priority Burst-time Arrival-time Waiting-time Finish-time Turnaround-time
1 p1 3 20 2 0 20 18
2 p2 5 30 3 20 50 47
3 p3 8 10 1 50 60 59
Average waiting time:23.333333

This post was written by: Rajendra Prasad
Rajendra Prasad is a professional blogger, web designer and front end web developer. Follow him on Facebook