-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-31
More file actions
48 lines (39 loc) · 1.08 KB
/
problem-31
File metadata and controls
48 lines (39 loc) · 1.08 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
#include <stdio.h>
void fifoPageReplacement(int pages[], int n, int capacity) {
int frames[capacity];
for (int i = 0; i < capacity; i++) {
frames[i] = -1;
}
int index = 0, pageFaults = 0;
for (int i = 0; i < n; i++) {
int found = 0;
for (int j = 0; j < capacity; j++) {
if (frames[j] == pages[i]) {
found = 1;
break;
}
}
if (!found) {
frames[index] = pages[i];
index = (index + 1) % capacity;
pageFaults++;
}
printf("Page: %d -> Frames: ", pages[i]);
for (int j = 0; j < capacity; j++) {
if (frames[j] != -1) {
printf("%d ", frames[j]);
} else {
printf("- ");
}
}
printf("\n");
}
printf("Total Page Faults: %d\n", pageFaults);
}
int main() {
int pages[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};
int n = sizeof(pages) / sizeof(pages[0]);
int capacity = 3;
fifoPageReplacement(pages, n, capacity);
return 0;
}