-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.Fifo.c
50 lines (42 loc) · 1.06 KB
/
2.Fifo.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
#include<stdio.h>
#define Frame_number 3
int FIFO(int pages[],int sz)
{
int frames[sz];
for(int i=0;i<sz;i++)frames[i]=-1;
int page_fault=0;
int victim=0;
for(int i=0;i<sz;i++){
int isFound=0;
for(int ii=0;ii<Frame_number;ii++){
if(frames[ii]==pages[i]){
isFound=1;
break;
}
}
if(!isFound){
int has_free_space=0;
for(int iii=0;iii<Frame_number;iii++){
if(frames[iii]==-1){
has_free_space=1;
frames[iii]=pages[i];
page_fault++;
break;
}
}
if(!has_free_space){
frames[victim]=pages[i];
victim=(victim+1)%Frame_number;
page_fault++;
}
}
}
return page_fault;
}
int main()
{
int pages[]={6,7,8,9,6,7,1,6,7,8,9,1};
int sz=sizeof(pages)/sizeof(pages[0]);
printf("\n Number of page Fault = %d\n",FIFO(pages,sz));
return 0;
}