Simulate the following page replacement algorithms FIFO

  #include<stdio.h>

#include<conio.h>
void main() 
{
int n,nf,i,j,ref[20],fr[20],count=0,k,hit,flag=0,pgf=0;
printf("Enter Number of pages : ");
scanf("%d",&n);
printf("Enter Page Numbers : ");
for(i=0;i<n;i++)
{
scanf("%d",&ref[i]);
}
printf("Enter the Number of frames : ");
scanf("%d",&nf);
printf("Ref. string\tPage frames\n");
for(i=0;i<n;i++)
{
fr[i]=-1;
}
for(i=0;i<n;i++)
{
flag=0;
printf("%d\t\t",ref[i]);
for(j=0;j<nf;j++)
{
if(fr[j]==ref[i])
{
flag=1;
 hit++;
break;
}
}
if(flag==0)
{
if(count>nf-1)
{
count=0;
fr[count]=ref[i];
count+=1;
pgf+=1;
}
else
{
fr[count]=ref[i];
count+=1;
pgf+=1;
}
for(k=0;k<nf;k++)
{
printf("%d\t",fr[k]);
}

}
printf("\n");
}
printf("Total page faults : %d\n",pgf);
}

Comments

Popular posts from this blog

CLOOK DISK SCHEDULING

LOOK Disk Scheduling