Home » NO IDEA » Page replacement algorithm FIFO,LRU

Page replacement algorithm FIFO,LRU

Blog Stats

  • 15,880 hits
April 2013
M T W T F S S
« Mar   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

#include<stdio.h>
int m,n,i,j,k,flag,count=0,refer[100],page_frame[100][2],fault=0,min,no_frames;
void replace(int z)
{
for(i=0;i<n;i++)
{
flag=1;
for(j=0;j<no_frames;j++)
if(refer[i]==page_frame[j][0])
{
m=j;
flag=0;
}
if(flag)
{
fault++;
min=32000;
for(j=0;j<no_frames;j++)
if(page_frame[j][1]<min)
{
min=page_frame[j][1];
k=j;
}
page_frame[k][0]=refer[i];
page_frame[k][1]=++count;
for(j=0;j<no_frames;j++)
printf("%d",page_frame[j][0]);
printf("\n");
}
else

{
printf("no page fault\n");
if(z==2)
page_frame[m][1]=++count;
}
}
printf("number of page fault is:%d\n",fault);
}
int main()
{
printf("\nEnter the number of reference:");
scanf("%d",&n);
printf("\nEnter the number of frames:");
scanf("%d",&no_frames);
printf("\nEnter the reference string:");
for(i=0;i<n;i++)
scanf("%d",&refer[i]);
printf("\t\t\tFIFO ALGORITHM \n");
for(i=0;i<no_frames;i++)
{
page_frame[i][0]=-1;
page_frame[i][1]=count;
}
replace(1);
fault=0;
count=0;
printf("\t\t\tLRU ALGORITHM \n");
for(i=0;i<no_frames;i++)
{
page_frame[i][0]=-1;
page_frame[i][1]=count;

}
replace(2);
return 0;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: