Program – FIFO page replacement algorithm

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
int fr[3];
void main()
{
void display();
int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};
int flag1=0,flag2=0,pf=0,frsize=3,top=0;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0;
flag2=0;
for(i=0;i<12;i++)
{
if(fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<frsize;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
fr[top]=page[j];
top++;
pf++;
if(top>=frsize)
top=0;
}
display();
}
printf("Number of page faults  : %d ",pf);
getch();
}
void display()
{
int i;
printf("\n");
for(i=0;i<3;i++)
printf("%d\t",fr[i]);
}

OUTPUT :
 2 -1 -1
 2  3 -1
 2  3 -1
 2  3  1
 5  3  1
 5  2  1
 5  2  4
 5  2  4
 3  2  4
 3  2  4
 3  5  4
 3  5  2

Number of page faults  : 6



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program – LRU page replacement algorithm
  2. C Program – Optimal Page Replacement Algorithm
  3. C Program – Implement the midpoint circle drawing algorithm
  4. C Program – Implement the Cohen-Sutherland line-clipping algorithm.
  5. C program to implement stack. Stack is a LIFO data strcuture LIFO – Last in First Out Perform PUSH(insert operation), POP(Delete operation) and Display stack

Leave a Comment

Previous post:

Next post: