0% found this document useful (0 votes)
5 views1 page

4) Fifo Page

The provided C program simulates a page replacement algorithm using a first-in-first-out (FIFO) strategy. It prompts the user to enter the number of pages and a page reference string, then tracks page faults as it fills a limited number of frames. The program outputs the current state of frames after each page insertion and the total number of page faults at the end.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

4) Fifo Page

The provided C program simulates a page replacement algorithm using a first-in-first-out (FIFO) strategy. It prompts the user to enter the number of pages and a page reference string, then tracks page faults as it fills a limited number of frames. The program outputs the current state of frames after each page insertion and the total number of page faults at the end.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int main() {
int pages[50], frames[10];
int n, f, i, j, pageFaults = 0, next = 0, found;

printf("Enter number of pages: ");


scanf("%d", &n);

printf("Enter the page reference string:\n");


for (i = 0; i < n; i++)
scanf("%d", &pages[i]);

printf("Enter number of frames: ");


scanf("%d", &f);

// Initialize frames to empty (-1)


for (i = 0; i < f; i++)
frames[i] = -1;

printf("\nPage Replacement Process:\n");

for (i = 0; i < n; i++) {


found = 0;

// Check if page is already in frames


for (j = 0; j < f; j++) {
if (frames[j] == pages[i]) {
found = 1;
break;
}
}

// If not found, it's a page fault


if (!found) {
frames[next] = pages[i];
next = (next + 1) % f; // Move to next frame
pageFaults++;

// Print current frames


printf("Insert %d: ", pages[i]);
for (j = 0; j < f; j++)
frames[j] == -1 ? printf("- ") : printf("%d ", frames[j]);
printf("\n");
}
}

printf("\nTotal Page Faults: %d\n", pageFaults);


return 0;
}

You might also like