Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

fifo page algorithm in C

#include <stdio.h>
int main()
{
int referenceString[10], pageFaults = 0, m, n, s, pages, frames;
printf("
Enter the number of Pages:	");
scanf("%d", &pages);
printf("
Enter reference string values:
");
for( m = 0; m < pages; m++)
{
   printf("Value No. [%d]:	", m + 1);
   scanf("%d", &referenceString[m]);
}
printf("
 What are the total number of frames:	");
{
   scanf("%d", &frames);
}
int temp[frames];
for(m = 0; m < frames; m++)
{
  temp[m] = -1;
}
for(m = 0; m < pages; m++)
{
  s = 0;
  for(n = 0; n < frames; n++)
   {
      if(referenceString[m] == temp[n])
         {
            s++;
            pageFaults--;
         }
   }     
   pageFaults++;
   if((pageFaults <= frames) && (s == 0))
      {
        temp[m] = referenceString[m];
      }   
   else if(s == 0)
      {
        temp[(pageFaults - 1) % frames] = referenceString[m];
      }
      printf("
");
      for(n = 0; n < frames; n++)
       {     
         printf("%d	", temp[n]);
       }
} 
printf("
Total Page Faults:	%d
", pageFaults);
return 0;
}
Source by learnprogramo.com #
 
PREVIOUS NEXT
Tagged: #fifo #page #algorithm #C
ADD COMMENT
Topic
Name
1+1 =