-
Notifications
You must be signed in to change notification settings - Fork 0
/
FifoPageReplacement.c
66 lines (66 loc) · 1.08 KB
/
FifoPageReplacement.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>
#include<conio.h>
#include<limits.h>
#define SIZE 100
int frames[20];
int pageString[SIZE];
int n,m;
int Faults()
{
int i,j;
int flag=0;
int count=0;
for(i=0;i<m;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(frames[j] == INT_MIN)
{
frames[j]=pageString[i];
flag=1;
count++;
break;
}
}
if(flag==1)
continue;
for(j=0;j<n;j++)
{
if(frames[j]==pageString[i])
{
flag=1;
break;
}
}
if(flag==1)
continue;
for(j=1;j<n;j++)
frames[j-1]=frames[j];
frames[j-1]=pageString[i];
count++;
}
return count;
}
void main()
{
printf("Enter the number of frames available\n");
scanf("%d",&n);
printf("Enter the size of the page string\n");
scanf("%d",&m);
int i;
for(i=0;i<n;i++)
{
frames[i]=INT_MIN;
}
printf("Enter the page string\n");
for(i=0;i<m;i++)
{
scanf("%d",&pageString[i]);
}
printf("Calculating the number of page faults...\n");
printf("The number of page faults are \n");
int pagefaults=Faults();
printf("%d\n",pagefaults);
getch();
}