0% found this document useful (0 votes)
14 views3 pages

Practical No - 09 - P

Uploaded by

anshaditi1129
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)
14 views3 pages

Practical No - 09 - P

Uploaded by

anshaditi1129
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

Practical No.

#include <stdio.h>

#define MAX_FRAMES 3

void fifoPageReplacement(int pages[], int n, int frames[])

int i, j, k, fault = 0;

int pointer = 0;

int isPageFault;

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

isPageFault = 1;

// Check if the page is already in a frame

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

if (frames[j] == pages[i])

isPageFault = 0;

break;

// If the page is not present, replace the oldest page with the current page

if (isPageFault)
{

frames[pointer] = pages[i];

pointer = (pointer + 1) % MAX_FRAMES;

fault++;

// Print the current state of the frames

printf("Page %d -> ", pages[i]);

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

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

printf("\n");

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

int main()

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

int n = sizeof(pages) / sizeof(pages[0]);

int frames[MAX_FRAMES] = {-1, -1, -1}; // Initialize frames with -1 (indicating empty frame)

printf("Page Reference Sequence: ");

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

printf("%d ", pages[i]);

printf("\n\nFIFO Page Replacement:\n");

fifoPageReplacement(pages, n, frames);
return 0;

OUTPUT:

Page Reference Sequence: 1 2 3 4 1 2 5 1 2 3 4 5

FIFO Page Replacement:

Page 1 -> 1 -1 -1

Page 2 -> 1 2 -1

Page 3 -> 1 2 3

Page 4 -> 4 2 3

Page 1 -> 4 1 3

Page 2 -> 4 1 2

Page 5 -> 5 1 2

Page 1 -> 5 1 2

Page 2 -> 5 1 2

Page 3 -> 5 1 3

Page 4 -> 4 1 3

Page 5 -> 4 5 3

Total Page Faults: 9

You might also like