Friday , September 30 2016
Home / C / C program for Least Recently Used (LRU) page replacement technique

C program for Least Recently Used (LRU) page replacement technique

Least recently used – LRU page replacement techique is a way to arrange pages in virtual memory so that page fault will be minimum. If page fault occur than pages that are least recently used are replace with new page.
Here is the program that implement LRU page replacement technique using C language.

#define MAX1 100

#define MAX2 10

int find_min(int count[], int size)

{

int pos,i;

pos=0;

for(i=1;i

{

if(count[i]

pos=i;

}

return pos;

}

void main()

{

int page[MAX1],frame[MAX2],i,j,count[MAX2],pfault=0,n,fsize,min,t=1,status=0;

clrscr();

printf(“Enter Total number of pages (MAX-100): “);

scanf(“%d”,&n);

printf(“\nEnter pages\n”);

for(i=0;i

{

scanf(“%d”,&page[i]);

}

printf(“Enter frame size (MAX 10): “);

scanf(“%d”,&fsize);

for(i=0;i

{

frame[i]=-1;

count[i]=0;

}

for(i=0;i

{

status=0;

for(j=0;j

{

if(page[i]==frame[j])

{

count[j]=t;

t++;

status=1;

}}

if(status==1)

goto A;

min=find_min(count,fsize);

count[min]=t++;

pfault++;

frame[min]=page[i];

A:for(j=0;j

printf(“%d\t”,frame[j]);

printf(“\n”);

}

printf(“\nPAGE FAULT is %d”,pfault);

getch();

OUTPUT 

tags: least recently used page replacement technique, page replacement algorithm, LRU algorith, implementation of LRU page replacement algo using C
Also See:   c program for pattern#14

Check Also

Hide Mouse Pointer C Program

How to Hide a Mouse Pointer Program in C : This program will show and hide ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.