forked from akkupy/codeDump
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLRUpage.c
74 lines (65 loc) · 1.49 KB
/
LRUpage.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
#include<stdio.h>
int main()
{
int i,j,pf=0,f=0,np,nf,c,k,m;
printf("enter the no. of pages: ");
scanf("%d",&np);
int ap[np][2];
printf("enter the page numbers: \n");
for ( i = 0; i < np; i++)
{
scanf("%d",&ap[i][0]);
ap[i][1]=i;
}
printf("enter the no. of frames: ");
scanf("%d",&nf);
int af[nf][2];
printf("enter the page numbers: \n");
for ( i = 0; i < nf; i++)
{
af[i][0]=-1;
}
for ( i = 0; i<np; i++)
{
c=0;
for ( j = 0; j<nf;j++)
{
if(ap[i][0]==af[j][0])
{
c=1;
af[j][1]=ap[i][1];
printf("%d \n",ap[i][0]);
break;
}
}
if(c!=1)
{
m=10000;
for(j=0;j<nf;j++)
{
if(af[j][0]==-1)
{
f=j;
break;
}
else
if(af[j][1]<m)
{
f=j;
m=af[j][1];
}
}
af[f][0]=ap[i][0];
af[f][1]=ap[i][1];
pf++;
printf("%d \t",ap[i][0]);
for ( k = 0; k<nf; k++)
{
printf("%d \t",af[k][0]);
}
printf("\n");
}
}
printf("page fault is %d",pf);
return 0;
}