The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Monday, August 15, 2011

FIFO Page Replacement Algorithm


#include<stdio.h>
#include<conio.h>
#define max 100
#define min 10

int ref[max],count,frame[min],n;

void input()
{
 int temp;
 do
 {
  clrscr();
  printf("\n\n\tEnter the number of page frames : ");
  scanf("%d",&n);
 }while(n>min || n <= 0);
 count = 0;
 printf("\n\n\tEnter the reference string (-1 for end) : ");
 scanf("%d",&temp);
 while(temp != -1 && count <= max)
 {
  ref[count++]=temp;
  scanf("%d",&temp);
 }
}

void FIFO()
{
 int i,j,fault=0;
 for(i=0;i<n;i++)
  frame[i] = -1;
 int ind,pos=0;
 printf("\n\nPage       Page Status          Page Fault      Frame Status\n");
 printf("-------------------------------------------------------------------------------");
 for(i=0;i<count;i++)
 {
  ind =0;
  printf("\n %d\t",ref[i]);
  for(j=0;j<n;j++)
  {
   if(frame[j] == ref[i])
   {
   printf("Already Inserted\t   No\t\t");
   ind = 1;
   break;
   }
  }
  if(ind == 0)
  {
   printf("Inserting in Frame\t   Yes\t\t");
   frame[pos] = ref[i];   pos = (pos+1)%n;
   fault ++;
  }
  for(j=0;j<n;j++)
  {
   if(frame[j] == -1)
    printf(" -");
   else
    printf(" %d",frame[j]);
  }
 }
 printf("\n\n\n\n\tEnd to inserting the reference string.");
 printf("\n\n\tTotal page fault is %d.",fault);
}


void main()
{
input();
FIFO();
getch();
}

No comments:

Post a Comment