Академический Документы
Профессиональный Документы
Культура Документы
$vim 5.c
#include<stdio.h>
typedef struct proc
{ int at,bt,status,t_bt;
int proc,est;
}P;
typedef struct et
{ int st,et,p;
}ET;
P p[15];
ET ti[40];
int z;//to maintain time count
int check(int n)
{ int i;
for(i=0;i<n;i++)
{ if(p[i].status==0)
return 1;
}
return 0;
}
void print_awt_atat(int n)
{ int i,j,flag,tat[15],wt[15];
float temp=0,atat=0,awt=0;
for(j=0;j<n;j++)
{ flag=1;
for(i=0;i<z;i++)
{
if(ti[i].p==j)
{ if(flag)
wt[j]=ti[i].st,flag=0;
temp=0;
while(ti[i+1].p!=j && i+1<z)
{ temp+=(ti[i+1].et-ti[i+1].st);
i++;
}
if(i+1<z)
wt[j]+=temp;
}
}
wt[j]-=p[j].at;
tat[j]=wt[j]+p[j].t_bt;
}
for(i=0;i<n;i++)
{
awt+=wt[i];
atat+=tat[i];
}
awt/=n*1.0;
atat/=n*1.0;
int main()
{ int n,i,qntm;
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;
p[i].t_bt=p[i].bt;
}
printf("\n\n\t\tEnter the Quantum Time : ");
scanf("%d",&qntm);
cal_proc(n,qntm);
print_awt_atat(n);
return 0;
/*===========================Out_put=================================*/
$cc 5.c
$./a.out
Enter the no of Process (max 15) : 4
Enter the arrivel time of process
process P0 : 5
process P1 : 0
process P2 : 4
process P3 : 3
/*==================================================================*/