/*
Write the simulation program for demand paging and show the page
scheduling and total number of page faults according to FIFO page
replacement algorithm. Assume memory of 'n' frames.
Request Page Numbers:
*/
#include<stdio.h>
#include<conio.h>
int RefString[20],PT[10],nof,nor;
void Accept()
{
int i;
printf("Enter Reference String: \n");
for(i=0;i<nor;i++)
{
printf("[%d]=",i);
scanf("%d",&RefString[i]);
}
}
int Search(int s)
{
int i;
for(i=0;i<nof; i++)
if(PT[i]==s)
return(i);
return(-1);
}
void FIFO()
{
int i,j,k=0,Faults=0;
for(i=0;i<nor;i++)
{
gotoxy(3*i+1,2);
printf("%2d",RefString[i]);
if(Search(RefString[i])==-1)
{
PT[k]=RefString[i];
for(j=0;j<nof;j++)
{
gotoxy(3*i+1,j+4);
if(PT[j])
{
printf("%2d",PT[j]);
}
}
Faults++;
k=(k+1)%nof;
}
}
gotoxy(10,18);
printf("Total Page Faults: %d",Faults);
getch();
}
void main()
{
clrscr();
printf("Enter Length of reference string: ");
scanf("%d",&nor);
printf("Enter No.of Frames: ");
scanf("%d",&nof);
clrscr();
Accept();
clrscr();
FIFO();
}
No comments:
Post a Comment