Program for FIFO page replacement algorithm

OUTPUT :
2 -1 -1
2  3 -1
2  3 -1
2  3  1
5  3  1
5  2  1
5  2  4
5  2  4
3  2  4
3  2  4
3  5  4
3  5  2

Number of page faults  : 6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
#include<conio.h>
int fr[3];
void main()
{
void display();
int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};
int flag1=0,flag2=0,pf=0,frsize=3,top=0;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0;
flag2=0;
for(i=0;i<12;i++)
{
if(fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<frsize;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
fr[top]=page[j];
top++;
pf++;
if(top>=frsize)
top=0;
}
display();
}
printf("Number of page faults  : %d ",pf);
getch();
}
void display()
{
int i;
printf("\n");
for(i=0;i<3;i++)
printf("%d\t",fr[i]);
}

OUTPUT :
2 -1 -1
2  3 -1
2  3 -1
2  3  1
5  3  1
5  2  1
5  2  4
5  2  4
3  2  4
3  2  4
3  5  4
3  5  2

Number of page faults  : 6

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

29 thoughts on “Program for FIFO page replacement algorithm

  1. can uplz give me the algorithm steps for scheduling algorithms(fcfs,sjf,priority,round robin0
    and also for page replacement algorithms(fifo,lru)

  2. can ani one help me ….”Write a program that implements the FIFO page- replacement algorithms.First, generate a random page reference string where page numbers range from 0 to 9. Apply the random page-reference string to each algorithm. Implement the replacement algorithms so that the number of page frames can vary from 1 to 7. Assume that demand paging is used. “

  3. jab na aaye na to program nai post karna chahiye !!!
    ache se padh le phir program post kareooo
    You know moron, How to calculate Page fault,if didn’t know then y u The bullshit are u doing…..A Poor Worker Alwaz Blame His Tools .

  4. Sorry but the program is incorrect it won’t give right answer unless you
    Replace line no. 18 from
    for(i=0;i<12;i++)
    To
    for(i=0;i<frsize;i++)

  5. And also there will be a line
    Pf++ just before line 33 because initially when we enter pages in frame array the page fault is considered because that page was not present there in the frames.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in