roundrobin
unknown
plain_text
2 years ago
1.2 kB
9
Indexable
#include<stdio.h>
struct process{
int pid;
int at;
int bt;
int rt;
int ct;
int tat;
int wt;
}process;
void main()
{
int n,t;
printf("ENTER NO OF PROCESSES");
scanf("%d",&n);
printf("ENTER THE TIME QUANTUM");
scanf("%d",&t);
struct process a[n];
printf("ENTER ARRIVAL TIME & BURST TIME OF");
for(int i=1;i<=n;i++)
{
printf("PROCESS %d",i);
a[i].pid=i;
scanf("%d%d",&a[i].at,&a[i].bt);
a[i].rt=a[i].bt;
}
roundrobin(a,n,t);
display(a,n);
}
void roundrobin(struct process a[],int n,int t)
{
int rp=n;
int time=0;
while (rp>0)
{
for(int i=0;i<n;i++)
{
if(a[i].rt>0)
{
int execute_time=a[i].rt;
if(a[i].rt<t){
execute_time=a[i].rt;
}
time+=execute_time;
a[i].rt=execute_time;
if(a[i].rt==0)
{
rp--;
a[i].ct=time;
a[i].tat=a[i].ct-a[i].at;
a[i].wt=a[i].tat-a[i].bt;
}
}
}
}
}
void display(struct process a[],int n){
float avg_tat=0;
float avg_wt=0;
printf("PID |\tAT |\tBT |\tCT |\tTAT |\tWT |");
for(int i=0;i<n;i++)
{
printf("%d/t,%d/t,%d/t,%d/t,%d/t,%d/t \n");
avg_tat+=a[i].tat;
avg_wt+=a[i].wt;
}
avg_tat=avg_tat/n;
avg_wt=avg_wt/n;
printf("\nAVG_TAT=%f",avg_tat);
printf("\nAVG_wT=%f",avg_wt);
}
Editor is loading...
Leave a Comment