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

FIFO

The document presents a C program implementing the First In First Out (FIFO) algorithm for page replacement. It processes an incoming stream of page requests and tracks the number of page faults while displaying the state of the frames after each request. The program ultimately reports a total of 4 page faults for the given input stream and frame size.

Uploaded by

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

FIFO

The document presents a C program implementing the First In First Out (FIFO) algorithm for page replacement. It processes an incoming stream of page requests and tracks the number of page faults while displaying the state of the frames after each request. The program ultimately reports a total of 4 page faults for the given input stream and frame size.

Uploaded by

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

First in First Out Algorithm for page replacement

#include < stdio.h >


int main()
{
int incomingStream[] = {4 , 1 , 2 , 4 , 5};
int pageFaults = 0;
int frames = 3;
int m, n, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
printf(" Incoming \ t Frame 1 \ t Frame 2 \ t Frame 3 ");
int temp[ frames ];
for(m = 0; m < frames; m++)
{
temp[m] = -1;
}
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(incomingStream[m] == temp[n])
{
s++;
pageFaults--;
}
}
pageFaults++;
if((pageFaults <= frames) && (s == 0))
{
temp[m] = incomingStream[m];
}
else if(s == 0)
{
temp[(pageFaults - 1) % frames] = incomingStream[m];
}
printf("\n");
printf("%d\t\t\t",incomingStream[m]);
for(n = 0; n < frames; n++)
{
if(temp[n] != -1)
printf(" %d\t\t\t", temp[n]);
else
printf(" - \t\t\t");
}
}
printf("\nTotal Page Faults:\t%d\n", pageFaults);
return 0;
}
Test it Now
Output:

Incoming Frame 1 Frame 2 Frame 3


44--
141-
2412
4412
5512
Total Page Faults: 4

You might also like