/* SHARANABASU G ANGADI */
/* Information Science & Engineering */
/* BEC Bagalkot , (Karnataka) INDIA. */
Write a C/C++ program to compute average waiting time and average turnaround
time for priority scheduling algorithm. The program should accept arrival time,
burst time and priority algorithm as input.
$vim 4.c
#include<stdio.h>
typedef struct proc
{ int at,bt,status;
int proc,est,pr;
}P;
P p[15];
int arr[15];
void cal_proc(int n)
{ int ct=0,i,j,k=0,epr=1,pros,ppr;
for(j=0;j<n;j++)
{ ppr=100;//To assign the last priority
for(i=0;i<n;i++)
{
if(p[i].status==0 && p[i].at<=ct && p[i].pr<=ppr)
{ ppr=p[i].pr;
pros=i;
}
}
p[pros].status=1;
p[pros].est=ct;
ct+=p[pros].bt;
arr[k++]=pros;
}
}
int main()
{ int n,i,wt[15],tat[15];
float awt,atat;
printf("\n\n\t\tEnter the no of Process (max 15) : ");
scanf("%d",&n);
printf("\n\n\t\tEnter the arrivel time of process \n");
for(i=0;i<n;i++)
{ printf("\t\tprocess P%d : ",i);
scanf("%d",&p[i].at);
}
printf("\n\n\t\tEnter the Burst time of process \n");
for(i=0;i<n;i++)
{ printf("\t\tprocess P%d : ",i);
scanf("%d",&p[i].bt);
p[i].status=0;
p[i].proc=i;
}
printf("\n\n\t\tEnter the Priority of process \n");
for(i=0;i<n;i++)
{ printf("\t\tprocess P%d : ",i);
scanf("%d",&p[i].pr);
}
cal_proc(n);
for(i=0;i<n;i++)
{ wt[i]=p[i].est-p[i].at;
awt+=wt[i];
tat[i]=(p[i].est-p[i].at)+p[i].bt;
atat+=tat[i];
}
awt/=n*1.0;
atat/=n*1.0;
printf("\n\tProc A_T B_T W_T TA_T\t");
printf("\n\t______________________________________\n\n");
for(i=0;i<n;i++)
printf("\t%d\t%d\t%d\t%d\t%d\n",p[i].proc,p[i].at,p[i].bt,wt[i],tat[i]);
printf("\n\t_______________________________________\n");
printf("\n\n\t\tAverage Waiting time = %f\n",awt);
printf("\n\n\t\tAverage Turn around time = %f\n",atat);
return 0;
}
/*===========================Out_put=================================*/
$cc 4.c
$./a.out
Enter the no of Process (max 15) : 4
Enter the arrivel time of process
process P0 : 5
process P1 : 3
process P2 : 0
process P3 : 4
Enter the Burst time of process
process P0 : 4
process P1 : 5
process P2 : 3
process P3 : 7
Enter the Priority of process
process P0 : 3
process P1 : 2
process P2 : 0
process P3 : 1
Proc A_T B_T W_T TA_T
______________________________________
0 5 4 10 14
1 3 5 0 5
2 0 3 0 3
3 4 7 4 11
_______________________________________
Average Waiting time = 3.500000
Average Turn around time = 8.250000
/*======================Out_put======================================*/