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


31 Responses to “Program for FIFO page replacement algorithm”

    • #include
      void main()
      {
      int n,p,a[10],f[10],i,j=0;
      cout<>p;
      cout<>n;
      cout<<"\n enter process string:";
      for(i=0;i>a[i];
      }
      for(i=0;i<n;i++)
      {
      f[i]=0;
      }
      while(j<p)
      {

      f[0]=a[j];
      for(i=0;i<n;i++)
      {
      cout<<f[i]<<",";
      }
      cout<=0;i–)
      {
      f[i]=f[i-1];
      }

      j++;
      }
      }

      Try this. If you need any other programs contact me.

      Reply
  1. 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. “

    Reply
  2. anyone help me to write java coding for working set clock page replacement algorithm

    Reply
  3. Rex_of_linux

    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 .

    Reply
  4. anum bakhtiar

    hey all i need simulation of not recently used page replacement in c or c++
    help me in this …….. if some one have then send me on my mail
    [email protected]

    Reply
  5. Aditya pareek

    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++)

    Reply
  6. Aditya pareek

    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.

    Reply

Leave a Reply