OS 7th PROGRAM
OS 7th PROGRAM
#include <stdio.h>
#define MAX_PAGES 3
int main() {
int pageSequence[] = {0, 1, 2, 3, 0, 4, 2, 1, 0, 3};
int n = sizeof(pageSequence) / sizeof(pageSequence[0]);
return 0;
}
// If the page is not in the page table, replace the oldest page
if (!pageFound) {
int oldestPageIndex = 0;
Output:
#include <stdio.h>
#define MAX_PAGES 3
int main() {
int pageSequence[] = {0, 1, 2, 3, 0, 4, 2, 1, 0, 3};
int n = sizeof(pageSequence) / sizeof(pageSequence[0]);
return 0;
}
break;
}
}
// If the page is not in the page table, replace the least recently used page
if (!pageFound) {
int lruPageIndex = 0;
// Find the index of the least recently used page in the page table
for (int j = 1; j < MAX_PAGES; j++) {
if (pageOrder[j] < pageOrder[lruPageIndex])
lruPageIndex = j;
}
// Replace the least recently used page with the current page
pageTable[lruPageIndex] = currentPage;
pageOrder[lruPageIndex] = i + 1;
pageFaults++;
#define MAX_PAGES 3
#define INFINITY 999999
int main() {
int pageSequence[] = {0, 1, 2, 3, 0, 4, 2, 1, 0, 3};
int n = sizeof(pageSequence) / sizeof(pageSequence[0]);
return 0;
}
if (!found) {
return currentPage;
}
}
if (optimalPage != -1) {
// Replace the page with the longest future access time
for (int j = 0; j < MAX_PAGES; j++) {
if (pageTable[j] == optimalPage) {
pageTable[j] = currentPage;
break;
}
}
}
pageFaults++;
Output: