-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIFO.c
More file actions
54 lines (48 loc) · 1.24 KB
/
FIFO.c
File metadata and controls
54 lines (48 loc) · 1.24 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
#include <stdio.h>
int main()
{
int incomingStream[] = {4, 1, 2, 4, 5};
int pageFaults = 0;
int frames = 3;
int i, j, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
printf("Incoming \t Frame 1 \t Frame 2 \t Frame 3");
int temp[frames];
for(i = 0; i < frames; i++)
{
temp[i] = -1;
}
for(i = 0; i < pages; i++)
{
s = 0;
for(j = 0; j < frames; j++)
{
if(incomingStream[i] == temp[j])
{
s++;
pageFaults--;
}
}
pageFaults++;
if((pageFaults <= frames) && (s == 0))
{
temp[i] = incomingStream[i];
}
else if(s == 0)
{
temp[(pageFaults - 1) % frames] = incomingStream[i];
}
printf("\n");
printf("%d\t\t\t",incomingStream[i]);
for(j = 0; j < frames; j++)
{
if(temp[j] != -1)
printf(" %d\t\t\t", temp[j]);
else
printf(" - \t\t\t");
}
}
printf("\nTotal page hits:\t%d",(pages-pageFaults));
printf("\nTotal Page Faults:\t%d\n", pageFaults);
return 0;
}