OS Lab 9 22BLC1230
OS Lab 9 22BLC1230
25/03/25
RegNo: 22BLC1230
____________________________________________________________________________
________
Device a c program to implement LRU, FIFO, optimal replacement algorithms. All frames are
initially empty. DIsplay the number of page faults by getting the page reference string and the
number of frames from the user. Display the sequence of occurrence of page faults.
Code
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
#include <stdlib.h>
#define MAX_FRAMES 20
#define MAX_PAGES 50
return pageFaults;
}
return pageFaults;
}
// Replace the page that won't be used for the longest time
if (distance == INT_MAX) {
replaceIndex = j;
break;
}
frames[replaceIndex] = pages[i];
}
// Store page fault information
faultSequence[*faultCount] = (PageFaultInfo){
.page = pages[i],
.index = i,
.currentFrames = currentFramesCopy,
.numFrames = numFrames
};
(*faultCount)++;
return pageFaults;
}
int main() {
int pages[MAX_PAGES];
int numPages = 0;
int numFrames = 0;
int choice;
while (1) {
// Reset fault count
faultCount = 0;
return 0;
}
Output:
Frame Size = 3
FIFO
LRU
Optimal
Frame size = 4
FIFO
LRU
Optimal