-
Notifications
You must be signed in to change notification settings - Fork 0
/
lfu_pgrep.c
77 lines (77 loc) · 2.03 KB
/
lfu_pgrep.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
void main()
{
int q[20], p[50], c = 0, c1, d, f, i, j, k = 0, n, r, t, b[20], c2[20];
printf("Enter no of pages: ");
scanf("%d", &n);
printf("Enter the reference string: ");
for (i = 0; i < n; i++)
scanf("%d", &p[i]);
printf("Enter no of frames: ");
scanf("%d", &f);
q[k] = p[k];
printf("\n\t%d\n", q[k]);
c++;
k++;
for (i = 1; i < n; i++)
{
c1 = 0;
for (j = 0; j < f; j++)
{
if (p[i] != q[j])
c1++;
else
printf("\tHIT \n");
}
if (c1 == f)
{
c++;
if (k < f)
{
q[k] = p[i];
k++;
for (j = 0; j < k; j++)
printf("\t%d", q[j]);
printf("\n");
}
else
{
for (r = 0; r < f; r++)
{
c2[r] = 0;
for (j = i - 1; j < n; j--)
{
if (q[r] != p[j])
c2[r]++;
else
break;
}
}
for (r = 0; r < f; r++)
b[r] = c2[r];
for (r = 0; r < f; r++)
{
for (j = r; j < f; j++)
{
if (b[r] < b[j])
{
t = b[r];
b[r] = b[j];
b[j] = t;
}
}
}
for (r = 0; r < f; r++)
{
if (c2[r] == b[0])
q[r] = p[i];
printf("\t%d", q[r]);
}
printf("\n");
}
}
}
printf("\nThe no of page faults is %d", c);
printf("\n No. of hits is %d", n - c);
printf("\nHit ratio %.2f\n", (float)(n - c) / c);
}