0% found this document useful (0 votes)
7 views2 pages

Paging FIFO

Uploaded by

vipuldangat103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Paging FIFO

Uploaded by

vipuldangat103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

int main()
{
int pages, num, avail;
int i, j, k = 0;

// Getting input from the user.


printf("Enter the total number of pages:\n");
scanf("%d", &pages);
printf("Enter the total number of frames:\n");
scanf("%d", &num);

int refstring[pages], frames[num], fault = 0;

printf("Enter the values of pages in refstring:\n");


for(i=0;i<pages;i++)
{
scanf("%d",&refstring[i]);
}

// Initializing frames array to -1.


for(i=0;i<num;i++)
{
frames[i]=-1;
}

// Implementing the FIFO page replacement algorithm.


k=0;
for(i=0;i<pages;i++)
{
avail=0;
for(j=0;j<num;j++)
{
if(frames[j]==refstring[i])
{
avail=1;
break;
}
}

if(avail==0)
{
frames[k]=refstring[i];
k=(k+1)%num;
fault++;
}

// Printing the current state of frames.


printf("\nThe frames after the page %d is %d: ",i,refstring[i]);
for(j=0;j<num;j++)
{
if(frames[j]!=-1)
printf("%d ",frames[j]);
else
printf("- ");
}
}
printf("\nThe total number of page faults is: %d\n",fault);

return 0;
}

You might also like