-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLRU_pg.C
105 lines (99 loc) · 2.21 KB
/
LRU_pg.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* LRU PAGE REPLACEMENT */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int page[100], f[3]={'@','@','@'};
void main()
{
int i,n=0,j,pfn=0;
clrscr();
printf("Enter . to stop input.\n");
printf("Start entering pages. Press ant key to start!\n\nReady?");
getch();
clrscr();
printf("Enter : ");
for(i=0;i<100;i++)
{
char c;
if(i!=0) printf(",");
c = getche();
if(c==(char)'.')
{
clrscr();
printf("Enter : %d",page[0]);
for(j=1;j<n;j++)
{
printf(",%d",page[j]);
}
printf(".");
break;
}
page[i] = (int)((char)c - 48);
n++;
}
printf("\n\nProcessing..........");
printf("\nPage reference\tPage Fault\tFrame\n");
for(i=0;i<n;i++)
{
int k,pf=1;
printf("%d",page[i]);
for(j=0;j<3;j++)
{
if(f[j]==page[i])
{
pf=0;
pfn--;
break;
}
}
if(j>2) j=0;
for(k=j;k<2;k++)
{
f[k] = f[k+1];
}
f[2] = page[i];
printf("\t\t%d",pf);
printf("\t\t");
if(f[0]=='@') printf("_");
else printf("%d",f[0]);
for(j=1;j<3;j++)
{
if(f[j]=='@') printf(",_");
else printf(",%d",f[j]);
}
printf("\n");
delay(400);
pfn++;
}
printf("\nNumber of page faults : %d",pfn);
j=0;
printf("\nPress any key to exit.");
getch();
}
/* OUTPUT
Enter : 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1.
Processing..........
Page reference Page Fault Frame
7 1 _,_,7
0 1 _,7,0
1 1 7,0,1
2 1 0,1,2
0 0 1,2,0
3 1 2,0,3
0 0 2,3,0
4 1 3,0,4
2 1 0,4,2
3 1 4,2,3
0 1 2,3,0
3 0 2,0,3
2 0 0,3,2
1 1 3,2,1
2 0 3,1,2
0 1 1,2,0
1 0 2,0,1
7 1 0,1,7
0 0 1,7,0
1 0 7,0,1
Number of page faults : 12
Press any key to exit.
*/