-
Notifications
You must be signed in to change notification settings - Fork 12
/
_9b.lru.c
66 lines (66 loc) · 1.1 KB
/
_9b.lru.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
#include<stdio.h>
struct frames
{
int content,count;
}frame[100];
void main()
{
int i,j,k,p,f,page[100],cnt=1,min,pf=0,id=0;
printf("ENTER THE NUMBER OF PAGES : ");
scanf("%d",&p);
printf("ENTER THE REFERENCING STRING : ");
for(i=0;i<p;i++)
{
scanf("%d",&page[i]);
}
printf("ENTER THE NUMBER OF FRAMES : ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
frame[i].content = -1;
frame[i].count = 0;
}
printf("\nREFERENCING PAGE\tSTATUS\t\tFRAME CONTENT\n\n");
for(i=0;i<p;i++)
{
printf("\t%d\t\t",page[i]);
for(j=0;j<f;j++)
{
if(frame[j].content == page[i])
{
printf("HIT\t\t");
frame[j].count = cnt++;
break;
}
}
if(j==f)
{
printf("MISS\t\t");
if(id<f)
{
frame[id].content = page[i];
frame[id].count = cnt++;
id++;
}
else
{
min=0;
for(k=0;k<f;k++)
{
if(frame[k].count<frame[min].count)
min = k;
}
frame[min].content = page[i];
frame[min].count = cnt++;
}
pf++;
}
for(j=0;j<f;j++)
{
if(frame[j].content !=-1)
printf("%d\t",frame[j].count);
}
printf("\n");
}
printf("\nPAGE FAULT : %d\n",pf);
}