0% found this document useful (0 votes)
17 views

FIFO

This C program implements the FIFO (First In First Out) page replacement algorithm. It takes a sample page reference string as input and simulates the FIFO algorithm to track the contents of the frame table and calculate the number of page faults. It initializes an array to represent the frame table, iterates through the page references to check for hits and faults, and outputs the frame contents and total faults.

Uploaded by

Srimathi tj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

FIFO

This C program implements the FIFO (First In First Out) page replacement algorithm. It takes a sample page reference string as input and simulates the FIFO algorithm to track the contents of the frame table and calculate the number of page faults. It initializes an array to represent the frame table, iterates through the page references to check for hits and faults, and outputs the frame contents and total faults.

Uploaded by

Srimathi tj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

FIFO

#include <stdio.h>

#define MAX_FRAMES 3

int main()

int frames[MAX_FRAMES], page_faults = 0, num_frames = 0, num_pages = 8;

int page_references[] = {4, 1, 2, 4, 3, 2, 1, 5};

int i, j, k;

for (i = 0; i < MAX_FRAMES; i++)

frames[i] = -1;

for (i = 0; i < num_pages; i++)

int page = page_references[i];

int page_found = 0;

for (j = 0; j < MAX_FRAMES; j++)

if (frames[j] == page)

page_found = 1;

break;

}
if (!page_found)

frames[num_frames % MAX_FRAMES] = page;

num_frames++;

page_faults++;

printf("Page %d: [", page);

for (k = 0; k < MAX_FRAMES; k++)

if (frames[k] == -1)

printf(" ");

} else {

printf("%d", frames[k]);

if (k < MAX_FRAMES - 1)

printf("|");

printf("]\n");

printf("Total page faults: %d\n", page_faults);

return 0;

}
OUTPUT:

You might also like