#include <stdio.
h>
#define MAX_FRAMES 10
#define MAX_PAGES 30
int main() {
int frames, pages, i, j, page, page_faults = 0, index, found;
int reference_string[MAX_PAGES], frame[MAX_FRAMES], page_queue[MAX_FRAMES];
for (i = 0; i < MAX_FRAMES; i++) {
frame[i] = -1;
page_queue[i] = -1;
printf("Enter the number of frames: ");
scanf("%d", &frames);
printf("Enter the number of pages: ");
scanf("%d", &pages);
printf("Enter the reference string:\n");
for (i = 0; i < pages; i++) {
scanf("%d", &reference_string[i]);
for (i = 0; i < pages; i++) {
page = reference_string[i];
found = 0;
for (j = 0; j < frames; j++) {
if (frame[j] == page) {
found = 1;
break;
if (!found) {
page_faults++;
int empty_frame = -1;
for (j = 0; j < frames; j++) {
if (frame[j] == -1) {
empty_frame = j;
break;
if (empty_frame != -1) {
frame[empty_frame] = page;
} else {
for (j = 0; j < frames - 1; j++) {
frame[j] = frame[j + 1];
frame[frames - 1] = page;
printf("Frames after accessing page %d: ", page);
for (j = 0; j < frames; j++) {
printf("%d ", frame[j]);
printf("\n");
}
printf("\nTotal page faults: %d\n", page_faults);
return 0;
First-In, First-Out (FIFO) is a simple page replacement algorithm used in operating systems to
manage the pages in memory. It works based on the principle of handling the oldest page in memory
first, meaning the page that has been in memory the longest is the one that will be replaced when a
new page needs to be loaded.
Advantages of FIFO:
1. Simplicity: FIFO is easy to understand and implement because it works like a queue, where
the first item that enters is the first one to leave.
2. Fairness: All pages are treated equally, with no priority given to any page based on its usage.
Disadvantages of FIFO:
1. Poor Performance: FIFO can cause a high number of page faults, especially if the memory
frames are not large enough for the most frequently used pages. The page that has been in
memory the longest may not always be the least useful.
2. Belady’s Anomaly: FIFO can sometimes result in more page faults as the number of frames
increases, which is counterintuitive and a disadvantage in some cases.
3. Convoy Effect: A long-running process that is loaded into memory early can cause delays for
other processes, as it will be replaced only after all other pages have been processed.
Enter the number of frames: 3
Enter the number of pages: 8
Enter the reference string:
70120304