FIFO Page Replacement Algorithm C Program

By | November 3, 2016

Let us learn how to implement FIFO Page Replacement Algorithm in C programming language. This code for First In First Out Page Replacement makes use of arrays.

What is FIFO Page Replacement Algorithm?

When a page fault occurs, the OS has to remove a page from the memory so that it can fit in another page in the memory.

These page replacement algorithms are used in operating systems that support virtual memory management.

FIFO Page Replacement technique is one of the simplest one to implement amongst other page replacement algorithms. It is a conservative algorithm.

It is a low-overhead algorithm that maintains a queue to keep a track of all the pages in a memory.

When a page needs to be replaced, the page at the FRONT of the Queue will be replaced. The FIFO page replacement technique is not implemented in operating systems nowadays.

C Program To Implement FIFO Page Replacement Algorithm in OS


C Program To Implement FIFO Page Replacement Algorithm in OS

If you have any doubts or compilation errors in this C program to implement First In First Out Page Replacement Algorithm in operating system, let us know about it in the comment section below.

Recommended Programs
C Program For Optimal Page Replacement Algorithm
C Program For LFU Page Replacement Algorithm
C Program For LRU Page Replacement Algorithm
C Program To ImplementMulti-Level Feedback Queue Scheduling Algorithm
C Program For Round Robin Scheduling Algorithm
C Program To Implement Kruskal’s Algorithm
C Program To Generate Prime Numbers using Sieve of Eratosthenes Algorithm
C Program To Implement Caesar Cipher Algorithm
C Program For Hexadecimal To Binary Conversion
C Program To Find Factorial of a Number using Recursion

23 thoughts on “FIFO Page Replacement Algorithm C Program

    1. Tushar Soni Post author

      If on any consecutive request sequence containing n or fewer distinct page references, the conservative algorithm will incur n or fewer page faults.

  1. Mayank Mishra

    Amazing code. Finally I got a working code for fifo replacement. Thanks.

  2. Parag Vidhate

    The FIFO Page Replacement Algorithm is used by the VMX/VAX Operating Systems, along with some modifications.

  3. Sam

    Showing this errors:

    FIFO.c: In function ‘main’:
    FIFO.c:12: error: ‘i’ undeclared (first use in this function)
    FIFO.c:12: error: (Each undeclared identifier is reported only once
    FIFO.c:12: error: for each function it appears in.)
    I have declared “i” as an int , but shows funny results. Please fix it!!

  4. Sam

    I am trying to get Page Fault Percentage.
    I have added the below code but it shows 0 !! Can you help

    double fault_Per = page_faults/pages;

    printf(“\nPage Fault Percentage:\t%f\n”,fault_Per);

  5. AthropicDream

    This algorithm is incorrect:
    Try this: Frames = 3, Pages = 12, ref. sequence 2,3,2,1..
    The problem is here:
    temp[m] = reference_string[m];
    When the cycle reaches m = 3, it will try to put ‘1’ in temp[m=3] which would be frame #4 and that exceeds the size of the number of specified frames.

  6. Tanu

    The code has some mistake in line
    if((page_faults <= frames) && (s == 0))
    temp[m] = reference_string[m];
    Suppose the ref. sequence is 1,1,2,3,4
    then 1 is at temp[0] i.e temp is: 1,-1,-1, again 1 is a hit so nothing is done ,temp is again:1,-1,-1
    and 2 is at reference_string[2], here m=2, but it should be put at temp[1] not at temp[2];
    So below is the modified code;
    we take a variable k and initialize it to 0 in 1st line of main() function;
    int k=0;
    if((page_faults <= frames) && (s == 0))
    temp[k++] = reference_string[m];
    //this worked for me

  7. Toxic

    Hey, thanks. I was noticing the same issue and I was trying to figure out where I should put the “pointer” for which frame to replace. I appreciate it!

  8. nidhi nature

    Can you run this code for 3frames,20 strings,
    1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2,1,2,3,6 it should give 16 as page fault but it’s giving 8 so I didn’t understand.

  9. Rijin

    can u please explain the steps how it is being entered into the array and the use of page fault and s


Let's Discuss