Program for FIFO PAge Replacement Algorithm
#include<stdio.h>#include<conio.h>
void print(int a[],int n)
{
int i;
for(i=0;i<n;i++)
{ printf(" %d ", a[i]);}
printf("\n");
}
int search(int e,int a[],int n)
{
int i;
for(i=0;i<n;i++)
{
if(a[i]==e)
{return i;}
}
return -1;
}
int count(int a[],int n)
{
int count=0,i;
for(i=0;i<n;i++)
{
if(a[i]!=-1){count++;}
else{break;}
}
return count;
}
void main()
{
int prs[30],mm[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},prss,nf,i,j,loc,c,fi;
int pf=0;
clrscr();
printf("enter Main Memory Size(no. of frames):");
scanf("%d",&nf);
printf("enter page ref stream size:");
scanf("%d",&prss);
printf("enter page ref stream:");
for(i=0;i<prss;i++)
{
scanf("%d",&prs[i]);
}
//FIFO algo.
for(i=0,fi=0;i<prss;i++)
{
loc=search(prs[i],mm,nf);
if(loc==-1)
{
printf("-Page fault-");
pf++;
if(i<nf){loc=i;}
else
{
loc=fi;
}
mm[loc]=prs[i];
if(fi<nf&&i>=nf){fi=loc+1;}
if(fi==nf){fi=0;}
}
print(mm,nf);
}
printf("\nTotal No. of page faults:%d",pf);
getch();
}
OUTPUT
No comments:
Post a Comment