Sunday, October 18, 2015

C Program to implement First In First Out (FIFO) page replacement algorithm.

/* ================================================================================
 *  * *
 *  * *       Filename:  fifo.c
 *  * *        Created:  Tuesday 24 March 2015
 *  * *       Compiler:  gcc
 *  * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 *  * *   Organization:  SCIS,University of Hyderabad
 *  * *
 *  ===============================================================================*/
#include<stdio.h>
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n======================================================");
printf("\nEnter the number of pages:");
scanf("%d",&n);
printf("Enter the page numbers :\n");
for(i=1;i<=n;i++)
scanf("\t %d",&a[i]);
printf("\n======================================================");
printf("\nEnter the number of frames :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= 0;
j=0;
printf("======================================================\n");
printf("Page Number\tPage frames\n");
printf("- - - - - -\t- - - - - -\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("======================================================\n");
printf("Page Fault is: %d",count);
printf("\n======================================================\n");
return 0;
}

No comments:

Post a Comment