FIFO Page replacement Algorithm in Python

FIFO in OS

FIFO Page Replacement Algorithm in Python

 

FIFO is an acronym for First in First Out in the case of an operating system. The concept is a page replacement technique used to switch data to and from and the main memory. The technique replaces the page from the queue which was first inserted. The operating system uses this concept to switch memory chunks, also known as the pages from the secondary memory to the main memory.

The approach is implemented in every operating system with the help of an algorithm. Such an algorithm is known as the scheduling algorithm and is used to assign processing time to every process which is in the waiting state.

Program in Python

#Python programming code to implement a FIFO algorithm.

from NodeList import Node

class PrepInsta:

    def __init__(s):

    s.head = None

#code to define the Queue 

   def enqueueQLL(s,item):

   temp = Node(str(item))

#assigning node to the temproary variable 

   temp.setNext(s.head)

   s.nodehead = temp

#assigning data to the node 

  qlength = max(len(node.data) for node in s.allNodes()) if s.head else 0

  print('\u2510{}\u250c'.format(' '*length))

  for node in s.allNodes():

     print('\u2502{:<{}}\u2502'.format(node.data, length))

     print('\u2514{}\u2518'.format('\u2500'*length))

#class defining NodeList
#driver code

class PrepInstaNode:

#code to initialize data 
    def __init__(s,initdata):

        s.data = initdata

        s.next = None
#code to input data 

    def getData(sf):

        return s.data
#code to set pointer 
    def getNext(s):

        return s.next

#code to assign data 

    def setData(s,new):

        s.data = new
#code to assign pointer 
    def setNext(s,newnext):

        s.next = newnext

Output –

q = QueueLL()

q.enqueueQLL(‘A’)

q.enqueueQLL(‘B’)

The queue will contain elements:

B

A