/****************************************************************************/
Name : Alveena P Babu Date : 01/02/2024
FIFO PAGE REPLACEMENT ALGORITHM
Roll No : 08 Experiment No : 19
/****************************************************************************/
PROGRAM
#include<stdio.h>
void main()
{
int pages,frames,ref[40],frame[40],k=0,i,j,res=0,temp,min,pos=0;
int hit_fifo=0,fault_fifo=0;
printf("\n Enter the Size of Page Refrence String : ");
scanf("%d",&pages);
printf("\n Enter the Page Reference String : ");
for(i=0;i<pages;i++)
scanf("%d",&ref[i]);
printf("\n Enter the Number of Frames : ");
scanf("%d",&frames);
printf("\n\nFIFO PAGE REPLACEMENT\n");
for(i=0;i<frames;i++)
frame[i]=-1;
printf("\nPage Reference\t\tPage Frames\n\n");
for(i=0;i<pages;i++)
{
res=0;
printf("For Page %d -> ",ref[i]);
for(j=0;j<frames;j++)
{
if(frame[j]==ref[i])
{
hit_fifo++;
res=1;
break;
}
}
if(res==1)
{
for(j=0;j<frames;j++)
if(frame[j]!=-1)
printf("\t%d",frame[j]);
else
printf("\t");
printf("\tHIT ");
}
if(res==0)
{
fault_fifo++;
frame[k]=ref[i];
k=(k+1)%frames;
for(j=0;j<frames;j++)
if(frame[j]!=-1)
printf("\t%d",frame[j]);
else
printf("\t");
printf("\tFAULT ");
}
printf("\n");
}
printf("\n Number of Page Faults -> %d",fault_fifo);
int hit_ratio=(hit_fifo*100)/pages;
int miss_ratio=(fault_fifo*100)/pages;
printf("\n Hit Ratio -> %d%%",hit_ratio);
printf("\n Miss Ratio -> %d%%\n",miss_ratio);
}
/****************************************************************************/
/****************************************************************************/
OUTPUT
Enter the Size of Page Refrence String : 10
Enter the Page Reference String : 1 2 3 1 2 3 4 5 1 4
Enter the Number of Frames : 3
FIFO PAGE REPLACEMENT
Page Reference Page Frames
For Page 1 -> 1 FAULT
For Page 2 -> 1 2 FAULT
For Page 3 -> 1 2 3 FAULT
For Page 1 -> 1 2 3 HIT
For Page 2 -> 1 2 3 HIT
For Page 3 -> 1 2 3 HIT
For Page 4 -> 4 2 3 FAULT
For Page 5 -> 4 5 3 FAULT
For Page 1 -> 4 5 1 FAULT
For Page 4 -> 4 5 1 HIT
Number of Page Faults -> 6
Hit Ratio -> 40%
Miss Ratio -> 60%
/****************************************************************************/