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

Pra15 OS

This document contains code for implementing a page replacement algorithm. The code first defines a function to check if a page is already in memory. It then defines the main function, which contains a reference string, frame array to store pages, and variables to count frames and page faults. It iterates through the reference string, checks for page faults, and either adds new pages or replaces existing pages following a FIFO policy. Finally, it prints the current pages and total page faults.

Uploaded by

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

Pra15 OS

This document contains code for implementing a page replacement algorithm. The code first defines a function to check if a page is already in memory. It then defines the main function, which contains a reference string, frame array to store pages, and variables to count frames and page faults. It iterates through the reference string, checks for page faults, and either adds new pages or replaces existing pages following a FIFO policy. Finally, it prints the current pages and total page faults.

Uploaded by

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

Practical no 15: Implement page replacement algorithm

Practical code:
#include <stdio.h>
#define MAX_FRAMES 3
int isPageInMemory(int page, int frames[], int frameCount) { for (int i
= 0; i < frameCount; i++) { if (frames[i] == page) {
return 1;
} }
return 0;
}
int main() {
int referenceString[] = {1, 2, 3, ,2,1,5,2,1,6,2,5,6,3,1,3,6,1,2,4,3}; int
frameCount = 0; int frames[MAX_FRAMES];
int pageFaults = 0; for (int i = 0; i <
MAX_FRAMES; i++) { frames[i] = -1;
}
int referenceStringLength = sizeof(referenceString) / sizeof(referenceString[0]); for (int i
= 0; i < referenceStringLength; i++) { int page = referenceString[i]; if
(!isPageInMemory(page, frames, frameCount)) { if (frameCount < MAX_FRAMES)
{ frames[frameCount] = page; frameCount++;
} else {
for (int j = 0; j < frameCount - 1; j++) {
frames[j] = frames[j + 1];
}
frames[frameCount - 1] = page;
}
pageFaults++;
}
printf("Current Pages in Memory: "); for (int j
= 0; j < frameCount; j++) { printf("%d ",
frames[j]);
}
printf("\n");
}
printf("Total Page Faults: %d\n", pageFaults); return 0;}
Name : Abhijeet kamble Roll no. : 03

OUTPUT:

You might also like