This repository was archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_1.c
More file actions
76 lines (61 loc) · 1.33 KB
/
program_1.c
File metadata and controls
76 lines (61 loc) · 1.33 KB
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
// Program to demo LRU page replacement algorithm
#include <stdio.h>
int main()
{
int i,j,k,min,rs[25],m[10],count[10],flag[25],n,f,pf=0,next=1;
printf("Enter length of the reference string: ");
scanf("%d", &n);
printf("Enter the reference string: ");
for(i=0; i<n; i++)
{
scanf("%d", &rs[i]);
flag[i] = 0;
}
printf("Enter the number of frames: ");
scanf("%d", &f);
for(i=0; i<f; i++)
{
count[i] = 0;
m[i] = -1;
}
printf("\nLRU PageReplacement process--\n");
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(m[j] == rs[i])
{
flag[i] = 1;
count[j] = next;
next++;
}
}
if(flag[i] == 0)
{
if(i<f)
{
m[i] = rs[i];
count[i] = next;
next++;
}
else
{
min = 0;
for(j=1;j<f;j++)
if(count[min]>count[j])
min=j;
m[min] = rs[i];
count[min] = next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t", m[j]);
if(flag[i] == 0)
printf("PF No. -- %d" , pf);
printf("\n");
}
printf("\nThe number of page faults using LRU are %d\n",pf);
return 0;
}