Wednesday , April 23 2014
Latest Program
You are here: 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

Leave a Reply

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

*


1 × = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top