Create you own custom course. Learn How?

31
Oct

0

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

0 Flares Facebook 0 Twitter 0 Google+ 0 StumbleUpon 0 Pin It Share 0 LinkedIn 0 Filament.io 0 Flares ×
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
0 Flares Facebook 0 Twitter 0 Google+ 0 StumbleUpon 0 Pin It Share 0 LinkedIn 0 Filament.io 0 Flares ×

No Comments

Reply


+ 8 = eleven

0 Flares Facebook 0 Twitter 0 Google+ 0 StumbleUpon 0 Pin It Share 0 LinkedIn 0 Filament.io 0 Flares ×