-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifopage.c
81 lines (70 loc) · 1.38 KB
/
fifopage.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
#include<stdio.h>
int numberofpage,numberofframe,frame[10],list[20],pointer=0,found,fault;
void initialise()
{
for(int i=0;i<numberofframe;i++)
{
frame[i]=-1;
}
}
int check(int a)
{
int flag=0;
for(int i=0;i<numberofframe;i++)
{
if(a==frame[i])
{
flag=1;
}
}
return flag;
}
void print(int a)
{
printf("\n");
for(int i=0;i<numberofframe;i++)
{
printf("%d ",frame[i]);
}
printf(" Fault: %d ",fault);
if(a==0)
{
printf("Page Miss\n");
}
else
{
printf("Page Hit\n");
}
}
void replace(int a)
{
frame[pointer]=a;
pointer = (pointer+1)%numberofframe;
}
void main()
{
printf("\nEnter the number of search sequence that you wish to enter:\n");
scanf("%d",&numberofpage);
printf("\nEnter the pages in order of execution:\n");
for(int i=0;i<numberofpage;i++)
{
scanf("%d",&list[i]);
}
printf("\nEnter the number of frames:\n");
scanf("%d",&numberofframe);
initialise();
for(int i=0;i<numberofpage;i++)
{
found = check(list[i]);
if(found==0)
{
fault++;
replace(list[i]);
print(found);
}
else
{
print(found);
}
}
}