LRU PAGE REPLACEMENT ALGORITHM
#include<stdio.h>
#include<conio.h>
main()
{
int i, j , k, min, rs[25], m[10], count[10], flag[25], n, f, pf=0, next=1;
clrscr();
printf("Enter the length of reference string -- ");
scanf("%d",&n);
printf("Enter the reference string -- ");
for(i=0;i<n;i++)
{
scanf("%d",&rs[i]);
flag[i]=0;
}
printf("Enter the number of frames -- ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
count[i]=0;
m[i]=-1;
}
printf("\nThe Page Replacement process is -- \n");
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(m[j]==rs[i])
{
flag[i]=1;
count[j]=next;
next++;
}
}
if(flag[i]==0)
{
if(i<f)
{ m[i]=rs[i];
count[i]=next;
next++;
}
else
{ min=0;
for(j=1;j<f;j++)
if(count[min] > count[j])
min=j;
m[min]=rs[i];
count[min]=next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t", m[j]);
if(flag[i]==0)
printf("PF No. -- %d" , pf);
printf("\n");
}
printf("\nThe number of page faults using LRU are %d",pf);
getch();
}
INPUT
Enter the length of reference string -- 20
Enter the reference string -- 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Enter the number of frames -- 3
OUTPUT
The Page Replacement process is --
7 -1 -1 PF No. – 1
7 0 -1 PF No. – 2
7 0 1 PF No. – 3
2 0 1 PF No. – 4
2 0 1
2 0 3 PF No. – 5
2 0 3
4 0 3 PF No. – 6
4 0 2 PF No. – 7
4 3 2 PF No. – 8
0 3 2 PF No. – 9
0 3 2
0 3 2
1 3 2 PF No. – 10
1 3 2
1 0 2 PF No. – 11
1 0 2
1 0 7 PF No. – 12
1 0 7
1 0 7
The number of page faults using LRU are 12
More:
1.Write a C program to simulate the FIRST-FIT contiguous memory allocation technique.
2.Write a C program to simulate the BEST FIT contiguous memory allocation technique.
3.Write a C program to simulate the WORST-FIT contiguous memory allocation technique.
4.Write a C program to simulate paging technique of memory management.
5.Write a C program to simulate first page replacement algorithm.
6.Write a C program to simulate LRU page replacement algorithm.
7.Write a C program to simulate LFU page replacement algorithm.
8.Write a C program to simulate optimal page replacement algorithm.
More: