-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIFO.c
46 lines (46 loc) · 998 Bytes
/
FIFO.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
typedef struct frame
{
int page, time;
}frame;
int main(void) {
int nf,n,i,np,j;
scanf("%d",&n);
int req[n];
for(i=0;i<n;i++) {
scanf("%d",&req[i]);
}
int pf=0;
int temp, min, count=0;
scanf("%d",&nf);
frame f[nf];
for(i=0;i<nf;i++) {
f[i].page=-1;
}
for(i=0;i<n;i++) {
temp=req[i];
for(j=0;j<nf;j++) {
if(f[j].page!=-1&&f[j].page==temp)
break;
}
if(j<nf)
continue;
pf++;
if(count<nf) {
f[count].page=temp;
f[count].time=i;
count++;
continue;
}
min=0;
for(j=1;j<nf;j++) {
if(f[min].time>f[j].time) {
min=j;
}
}
f[min].page=temp;
f[min].time=i;
}
double miss=(double)pf/n, hit=1.0-miss;
printf("\nNo. of page fault : %d\nHit ratio : %.3lf\nMiss ratio : %.3lf\n",pf,hit,miss);
}