P 9
P 9
h>
void main()
{
int i,j=0,x=-1,k[10],m=0,n,t,s=0,d=0,c,e[10],f[10];
int a[50],temp,b[50],p[10],bur[10],bur1[10],min,max;
int wtime[10],ttime[10],ctime[10],atime[10],put,tottime,towtime;
float attime,awtime,thpt;
if(b[x] == 1)
{
p[s] = x;
k[s] = a[j+1];
s++;
}
j++;
b[x] -= 1;
printf(" P%d |", x+1);
}
else if(bur[x] != 0)
{
a[j+1] = a[j] + bur[x];
bur[x] = 0;
if(b[x] == 1)
{
p[s] = x;
k[s] = a[j+1];
s++;
}
j++;
b[x] = 1;
printf(" P%d |",x+1);
}
}
printf("\n");
temp = atime[i];
atime[i] = atime[j];
atime[j] = temp;
temp = k[i];
k[i] =k[j];
k[j] = temp;
temp = e[i];
e[i] = e[j];
e[j] = temp;
temp = f[i];
f[i] = f[j];
f[j] = temp;
}
}
}
}
for(i=0; i<n +1; i++)
{
ttime[-1]=0;
wtime[-1]=0;
wtime[i] = k[i] - bur1[i];
ctime[i] = k[i] ;
ttime[i] = ctime[i] - atime[i];
attime = attime + ttime[i];
awtime = awtime + wtime[i];
t= ctime[n-1];
}
tottime = towtime =0;
printf("\n");
for(i=0; i<85; i++)
printf("-");
printf("\n");
printf("| - | - | %3d | %3d | - |
- |",m,d);
printf("\n");
for(i=0; i<85; i++)
printf("-");
printf("\n\nAverage turn around time = Total Turn Around Time / No. of processes \
n=(");
for(i=1;i<n;i++){
printf("TT (P%d)+ ",i);
}
printf("TT (P%d))/%d \n= (",n,n);
for(i=0;i<(n-1);i++){
printf("%d+",ttime[i]);
}
attime = (float)tottime/n;
printf("%d)/%d \n= ",ttime[n-1],n);
printf("%d/%d \n=",tottime,n);
printf(" %.2f ms",attime);
printf("\nAverage waiting time = Total Waiting Time / No. of processes \n=(");
for(i=1;i<n;i++){
printf("WT (P%d) + ",i);
}
printf("WT (P%d))/%d \n= (",n,n);
for(i=0;i<(n-1);i++){
printf("%d+",wtime[i]);
}
awtime = (float)towtime/n;
printf("%d)/%d \n= ",wtime[n-1],n);
printf("%d/%d \n=",towtime,n);
printf(" %.2f ms",awtime);
printf("\nThroughtput = (No. of Process Completed / Total Time) \n= %d / %d \n=
%5.2f ms\n\n",n,t,(float)n/(float)t);
}
output
No. of cycles: 15
Time Wastage : 75 ms
Gantt Chart
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
| P1 | P2 | P3 | P4 | P5 | P6 | P7 | P8 |
P3 | P4 | P5 | P7 | P8 | P5 | P8 |
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
0 9 27 47 67 87 107 127 147
153 172 192 205 225 230 245
Process Table
-----------------------------------------------------------------------------------
--
| Time | Process | No.of | Wastage | Turnaround Time | Waiting Time
|
| | Completed | Cycle's | Second in ms | =(P.C-P.S) | =(T.T-B.T)
|
-----------------------------------------------------------------------------------
--
| 0 | - | - | - | - | -
|
| 9 | P1 | 1 | 11 | 7 | 0
|
| 27 | P2 | 1 | 2 | 22 | 9
|
| 153 | P3 | 2 | 1 | 147 | 127
|
| 172 | P4 | 3 | 15 | 168 | 133
|
| 230 | P5 | 2 | 7 | 227 | 185
|
| 205 | P7 | 1 | 20 | 203 | 185
|
| 107 | P6 | 2 | 14 | 106 | 74
|
| 245 | P8 | 3 | 5 | 241 | 190
|
-----------------------------------------------------------------------------------
--
Average turn around time = Total Turn Around Time / No. of processes
=(TT (P1)+ TT (P2)+ TT (P3)+ TT (P4)+ TT (P5)+ TT (P6)+ TT (P7)+ TT (P8))/8
= (7+22+147+168+227+203+106+241)/8
= 1121/8
= 140.12 ms
Processor Utilisation
= (Processor Busy Time / (Processor Busy Time + Processor Ideal Time))*100
= (245 /(245 + 0))*100
= (1/1)*100
= 100%