Tuesday, August 7, 2012

FIFO using Paging and Page Faults in C

Below is a Simple C Language Program Which shows simulation of demand paging & show page faults
  according to FIFO replacement


#include<stdio.h>
#include<conio.h>
int frames[]={-1,-1,-1};
int page_found(int pno)
{
 int i;
 for(i=0;i<3;i++)
 if(frames[i]==pno)
   return i;
 return -1;
}
void main()
{
 int i;
 int page_fault;
 int p_request[]={9,14,10,11,15,9,11,9,15,10,9,15,10,12,5};
 int size=15,page_faults=0;
 clrscr();
 printf("\n Page No.___Page_Frames");
 printf("\n_________________________\n");
 for(i=0;i<size;i++)
 {
  if(page_found(p_request[i]==-1))//next page is not in frame
  {
   frames[page_fault%3]=p_request[i];
   page_faults++;
   printf("%4d___%4d%4d%4d\n",p_request[i],frames[0],frames[1],frames[2]);
  }
  else
  printf("\n %4d",p_request[i]);
 }
 printf("\n_________________________\n");
 printf("\n Total Page Faults=%d",page_faults);
 getch();
}

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...