/* ================================================================================
* * *
* * * Filename: lru.c
* * * Created: Tuesday 24 March 2015
* * * Compiler: gcc
* * * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * * Organization: SCIS,University of Hyderabad
* * *
* ===============================================================================*/
#include<stdio.h>
int fr[3];
void main()
{
void display();
int n;
int p[100],t,i,j,fs[3];
printf("======================================================\n");
printf("Enter the number of pages:");
scanf("%d",&n);
printf("Enter the all PAGE number:\n");
for(t=0; t<n; t++)
{
scanf("%d",&p[t]);
}
printf("The PAGE numbers are:\n");
for(t=0; t<n; t++)
{
printf("%d\t",p[t]);
}
printf("\n======================================================\n");
int index,k,l,flag1=0,flag2=0,pf=0,frsize=3;
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<n;j++)
{
flag1=0,flag2=0;
for(i=0;i<3;i++)
{
if(fr[i]==p[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<3;i++)
{
if(fr[i]==-1)
{
fr[i]=p[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<3;i++)
fs[i]=0;
for(k=j-1,l=1;l<=frsize-1;l++,k--)
{
for(i=0;i<3;i++)
{
if(fr[i]==p[k])
fs[i]=1;
}
}
for(i=0;i<3;i++)
{
if(fs[i]==0)
index=i;
}
fr[index]=p[j];
pf++;
}
display();
}
printf("\n-----------------------------------------------------\n");
printf("\n\tTotal number of page faults :%d",pf);
printf("\n======================================================\n");
printf("\n");
}
void display()
{
int i;
printf("\n");
for(i=0;i<3;i++)
printf("\t%d",fr[i]);
}
* * *
* * * Filename: lru.c
* * * Created: Tuesday 24 March 2015
* * * Compiler: gcc
* * * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * * Organization: SCIS,University of Hyderabad
* * *
* ===============================================================================*/
#include<stdio.h>
int fr[3];
void main()
{
void display();
int n;
int p[100],t,i,j,fs[3];
printf("======================================================\n");
printf("Enter the number of pages:");
scanf("%d",&n);
printf("Enter the all PAGE number:\n");
for(t=0; t<n; t++)
{
scanf("%d",&p[t]);
}
printf("The PAGE numbers are:\n");
for(t=0; t<n; t++)
{
printf("%d\t",p[t]);
}
printf("\n======================================================\n");
int index,k,l,flag1=0,flag2=0,pf=0,frsize=3;
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<n;j++)
{
flag1=0,flag2=0;
for(i=0;i<3;i++)
{
if(fr[i]==p[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<3;i++)
{
if(fr[i]==-1)
{
fr[i]=p[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<3;i++)
fs[i]=0;
for(k=j-1,l=1;l<=frsize-1;l++,k--)
{
for(i=0;i<3;i++)
{
if(fr[i]==p[k])
fs[i]=1;
}
}
for(i=0;i<3;i++)
{
if(fs[i]==0)
index=i;
}
fr[index]=p[j];
pf++;
}
display();
}
printf("\n-----------------------------------------------------\n");
printf("\n\tTotal number of page faults :%d",pf);
printf("\n======================================================\n");
printf("\n");
}
void display()
{
int i;
printf("\n");
for(i=0;i<3;i++)
printf("\t%d",fr[i]);
}
No comments:
Post a Comment