Introduction to FIFO page replacement :
The simplest page-replacement algorithm is a first-in,first-out(FIFO)algorithm. A FIFO replacement algorithm associates with each page the time when that page was brought into memory. When a page must be replaced, the oldest page is chosen. Notice that it is not strictly necessary to record the time when a page is brought in. We can create a FIFO queue to hold all pages in memory. We replace the page at the head of the queue. When a page is brought into memory, we insert it at the tail of the queue.
C program for FIFO page replacement :
OUTPUT :
The simplest page-replacement algorithm is a first-in,first-out(FIFO)algorithm. A FIFO replacement algorithm associates with each page the time when that page was brought into memory. When a page must be replaced, the oldest page is chosen. Notice that it is not strictly necessary to record the time when a page is brought in. We can create a FIFO queue to hold all pages in memory. We replace the page at the head of the queue. When a page is brought into memory, we insert it at the tail of the queue.
C program for FIFO page replacement :
#include<stdio.h>
int main()
{
int
i,j,n,page[50],frameno,frame[10],move=0,flag,count=0;
float rate;
printf("Enter the number of
pages\n");
scanf("%d",&n);
printf("Enter the page
reference numbers\n");
for(i=0;i<n;i++)
scanf("%d",&page[i]);
printf("Enter the number of
frames\n");
scanf("%d",&frameno);
for(i=0;i<frameno;i++)
frame[i]=-1;
printf("Page reference
string\tFrames\n");
for(i=0;i<n;i++)
{
printf("%d\t\t\t",page[i]);
flag=0;
for(j=0;j<frameno;j++)
{
if(page[i]==frame[j])
{
flag=1;
printf("No
replacement\n");
break;
}
}
if(flag==0)
{
frame[move]=page[i];
move=(move+1)%frameno;
count++;
for(j=0;j<frameno;j++)
printf("%d\t",frame[j]);
printf("\n");
}
}
rate=(float)count/(float)n;
printf("Number of page faults
is %d\n",count);
printf("Fault rate is
%f\n",rate);
return 0;
}
No comments:
Post a Comment