C Program - FIFO Page Replacement Algorithm
Program code:
#include<stdio.h>
int main()
{
int k,nop,frame_size,i,j,temp=100,page_fault=0;
int page_name[20],frame[20];
int m,n=0,count=0;
printf("Enter the No. of pages\t");
scanf("%d",&nop);
printf("Enter the frame size\t");
scanf("%d",&frame_size);
printf("Enter page name\n");
for(i=0;i<nop;i++)
scanf("%d",&page_name[i]);
for(i=0;i<frame_size;i++)
frame[i]=0;
for(i=0,j=0;i<frame_size;i++,j++)
{
frame[j]=page_name[i];
page_fault++;
printf("\npage\t%d\t",page_name[i]);
printf("Frame\t");
for(k=0;k<frame_size;k++)
printf(" %d",frame[k]);
printf("\tPage fault till now:\t");
printf("%d",page_fault);
}
j=0;
for(m=i;m<nop;m++)
{
if(page_name[m]==frame[j])
{
j++;
count++;
printf("\npage\t%d\t",page_name[m]);
printf("Frame\t");
for(k=0;k<frame_size;k++)
printf(" %d",frame[k]);
printf("\tPage fault till now:\t");
printf("%d",page_fault);
}
else
{
frame[j]=page_name[m];
page_fault++;
j++;
count++;
printf("\npage\t%d\t",page_name[m]);
printf("Frame\t");
for(k=0;k<frame_size;k++)
printf(" %d",frame[k]);
printf("\tPage fault till now:\t");
printf("%d",page_fault);
}
if(count==frame_size)
j=0;
}
return 0;
}
Output:
Program code:
#include<stdio.h>
int main()
{
int k,nop,frame_size,i,j,temp=100,page_fault=0;
int page_name[20],frame[20];
int m,n=0,count=0;
printf("Enter the No. of pages\t");
scanf("%d",&nop);
printf("Enter the frame size\t");
scanf("%d",&frame_size);
printf("Enter page name\n");
for(i=0;i<nop;i++)
scanf("%d",&page_name[i]);
for(i=0;i<frame_size;i++)
frame[i]=0;
for(i=0,j=0;i<frame_size;i++,j++)
{
frame[j]=page_name[i];
page_fault++;
printf("\npage\t%d\t",page_name[i]);
printf("Frame\t");
for(k=0;k<frame_size;k++)
printf(" %d",frame[k]);
printf("\tPage fault till now:\t");
printf("%d",page_fault);
}
j=0;
for(m=i;m<nop;m++)
{
if(page_name[m]==frame[j])
{
j++;
count++;
printf("\npage\t%d\t",page_name[m]);
printf("Frame\t");
for(k=0;k<frame_size;k++)
printf(" %d",frame[k]);
printf("\tPage fault till now:\t");
printf("%d",page_fault);
}
else
{
frame[j]=page_name[m];
page_fault++;
j++;
count++;
printf("\npage\t%d\t",page_name[m]);
printf("Frame\t");
for(k=0;k<frame_size;k++)
printf(" %d",frame[k]);
printf("\tPage fault till now:\t");
printf("%d",page_fault);
}
if(count==frame_size)
j=0;
}
return 0;
}
Output:
Thank you very much for your code
ReplyDelete