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

Fifo

Uploaded by

yashrajrjo5
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)
18 views2 pages

Fifo

Uploaded by

yashrajrjo5
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

5:47 .. .

_E'C'WI,
~

OS-Lab-Manual 2021-22 v c!J


AIM: To implement page replacement algorithms FIFO (First In
First Out)
/* FIFO PAGE REPLACEMENT ALGORITHM */
Step 1: Create a queue to hold all pages in memory
Step 2: When the page is required replace the page at the head of the
queue
Step 3: Now the new page is inserted at the tail of the queue
/*PROGRAM*/
#include<stdio.h>
#include<conio.h>
int ij,nof,nor,flag=0,refI 50],frm[50],pf=0, victim=- I;
void main()
{
clrscr();
printf("\n \t\t\t FIFI PAGE REPLACEMENT ALGORITHM");
printf("\n Enter no.of frames ....");
scanf("¾d",&nof);
printf("Enter number of reference string..\n");
scanf("¾d" ,&nor);
printf("\n Enter the reference string.. ");
for(i=0;i<nor;i++)
scanf("¾d" ,&refii]);
printf("\nThe given reference string:");
for(i=0;i<nor;i++)
printf("%4d" ,refii]);
for(i= 1;i<=nof;i++)
frm[i]=-1;
printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
printf("\n\t Reference np¾d->\t" ,refii]);
for(j=0;j<nof;j++)
{
if(frm[j]==refii])
{
flag=l;
break;
}}
if(flag 0)
{
pf++;
victim++;
victim=victim¾nof;
frm[ victim]=refii];
for(j=0;j<nof;j++)
printf("%4d" ,frm[j]);
}}
printf("\n\n\t\t No.of pages faults ...%d" ,pf);
getch(); }
OUTPUT:
FIFO PAGE REPLACEMENT ALGORITHM
Enter no.of frames ... .4
Enter number of reference string..
6
printf("\n\t Reference np%d->\t" ,ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]-ref[ i])
{
flag=l;
break;
}}
if(flag 0)
{
pf++;
victim++;
victim=victim%nof;
fun[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d" ,frm[j]);
}}
printf("\n\n\t\t No.of pages faults ...%d" ,pf);
getch(); }
OUTPUT:
FIFO PAGE REPLACEMENT ALGORITHM
Enter no.of frames ... .4
Enter number of reference string..
6
Enter the reference string..
564123
The given reference string:
5 6 4 1 2 3

I
Reference np5-> 5 -1 -1 -1
Reference np6-> 5 6 -1 -1
Reference np4-> 5 6 4 -1
Reference np 1-> 5 6 4 1
Reference np2-> 2 6 4 1
Reference np3-> 2 3 4 1
No.of pages faults ... 6

You might also like