This C program implements the Least Recently Used (LRU) page replacement algorithm. It takes in the number of frames and page references as input, stores the references in an array, and simulates replacing pages according to the LRU logic. It outputs the frames after each reference and the total page faults. The findLRU function finds the least recently used page based on the time array, and the main function handles iterating through the references, tracking hits/faults, and calling findLRU on a page fault.
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Lab9 LRU and FIFO.docx
1. #include <stdio.h>
int findLRU(int time[], int n)
{
int i, minimum = time[0], pos = 0;
for (i = 1; i < n; ++i)
{
if (time[i] < minimum)
{
minimum = time[i];
pos = i;
}
}
return pos;
}
//main function
int main()
{
int f, n, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j, pos, faults = 0, count=0,
k, avail,ch;
char h[10]="hit", pf[10]="fault";
printf("Enter number of frames: ");
scanf("%d", &f);
printf("Enter number of pages: ");
scanf("%d", &n);
printf("Enter reference string: ");
for (i = 0; i < n; ++i)
{
scanf("%d", &pages[i]);
}
printf(" select the Page replacement algorithm:n 1. LRU n 2.FIFO n");
printf("enter your choice:");
scanf("%d", &ch);
switch(ch)
{
case 1:
for (i = 0; i < f; ++i)
{
frames[i] = -1;
}