This C program simulates a First-In First-Out (FIFO) page replacement algorithm. It takes a sample reference string as input and checks each page access against a fixed number of frames. If the page is not already in frames, it causes a page fault. The oldest page in frames is replaced with the new page. The program outputs the reference string, the frames after each access, and the total number of page faults.
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 ratings0% found this document useful (0 votes)
14 views2 pages
FIFO Page Replacement
This C program simulates a First-In First-Out (FIFO) page replacement algorithm. It takes a sample reference string as input and checks each page access against a fixed number of frames. If the page is not already in frames, it causes a page fault. The oldest page in frames is replaced with the new page. The program outputs the reference string, the frames after each access, and the total number of page faults.
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/ 2
#include <stdio.
h>
#define MAX_FRAMES 3 // Number of frames in memory
// Function to check if a page exists in frames
int isPagePresent(int frames[], int frameSize, int page) { for (int i = 0; i < frameSize; i++) { if (frames[i] == page) { return 1; // Page found in frames } } return 0; // Page not found in frames }
int main() { int referenceString[] = {7,0,1,2,0,3,0,4,2,3,0,3,1,2,0}; // Example reference string int numReferences = sizeof(referenceString) / sizeof(referenceString[0]);
int frames[MAX_FRAMES]; // Array to hold frames in memory
int framePointer = 0; // Points to the oldest frame in FIFO
int pageFaults = 0; // Counter for page faults
// Initialize frames array with -1 (indicating empty frame)
for (int i = 0; i < MAX_FRAMES; i++) { frames[i] = -1; }
printf("Page Reference String: ");
for (int i = 0; i < numReferences; i++) { printf("%d ", referenceString[i]); } printf("\n\n");