-
Notifications
You must be signed in to change notification settings - Fork 0
/
lrupage.c
78 lines (69 loc) · 1.22 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
75
76
77
78
#include <stdio.h>
int search[15],frame[10],priority[10];
int numberofsearch,framesize,location;
int fault=0,count=1;
int searchframe(int a)
{
int flag=0;
for(int i=0;i<framesize;i++)
{
if(frame[i]==a)
{
flag=1;
location=i;
}
}
return flag;
}
int position()
{
int small=100,index;
for(int i=0;i<framesize;i++)
{
if(priority[i]<small)
{
small = priority[i];
index = i;
}
}
return index;
}
void main()
{
printf("\nEnter the number of search sequence:\n");
scanf("%d",&numberofsearch);
printf("Enter the search sequence in order\n");
for(int i=0;i<numberofsearch;i++)
{
scanf("%d",&search[i]);
}
printf("Enter the size of the frame:\n");
scanf("%d",&framesize);
for(int i=0;i<framesize;i++)
{
frame[i] = -1;
priority[i] = -1;
}
for(int i=0;i<numberofsearch;i++)
{
if(searchframe(search[i]))
{
frame[location] = search[i];
priority[location] = count;
count++;
}
else
{
fault++;
int index = position();
frame[index] = search[i];
priority[index] = count;
count++;
}
for(int j=0;j<framesize;j++)
{
printf("%d ",frame[j]);
}
printf("Page Fault: %d\n",fault);
}
}