0% found this document useful (0 votes)
91 views

C Program For FIFO Page Replacement Algorithm

The document describes a C program that implements a FIFO (first-in, first-out) page replacement algorithm. The program takes in the number of pages and page references as input, along with the number of frames. It simulates the page faults by checking if the referenced page is already in the frame table and replacing the oldest page based on FIFO if needed. The program outputs the reference string and frame contents at each step, and the total number of page faults.

Uploaded by

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

C Program For FIFO Page Replacement Algorithm

The document describes a C program that implements a FIFO (first-in, first-out) page replacement algorithm. The program takes in the number of pages and page references as input, along with the number of frames. It simulates the page faults by checking if the referenced page is already in the frame table and replacing the oldest page based on FIFO if needed. The program outputs the reference string and frame contents at each step, and the total number of page faults.

Uploaded by

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

C program for FIFO page replacement algorithm

#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("Page Fault Is %d",count);
return 0;
}
OUTPUT :

ENTER THE NUMBER OF PAGES:


12

ENTER THE PAGE NUMBER :


1
2
3
4
1
2
5
1
2
3
4
5

ENTER THE NUMBER OF FRAMES :4


ref string page frames
1 1 -1 -1 -1
2 1 2 -1 -1
3 1 2 3 -1
4 1 2 3 4
1
2
5 5 2 3 4
1 5 1 3 4
2 5 1 2 4
3 5 1 2 3
4 4 1 2 3
5 4 5 2 3
Page Fault Is 10

You might also like