C Program FIFO Page Replacement Policy : ExplanationPritesh
Program : [ Click Here ]
Step 1 : Accept Given Data .
- Frame Number : fno
- Number of Pages : count
- Actual Pages : arr
printf("nEnter the number of Frames : ");
printf("nEnter the number of Pages : ");
printf("nEnter the Page No : ");
Step 2 :
- Now we have Pages and Frame Size.
- Total Number of Pages is Given by Variable : “Count“.
- Now We are Creating Circular Linked List Whose Size is equal to “Frame Size“
- Initialize Each Node’s Data = -99.
- -99 Tells us That Place is Empty
- Call Create Function.
Size of Linked List = Frame Size
Step 3 :
- After Creating Initial Setup Call Function : fifo().
- While Inserting Element in Frame [i.e in Linked List ] We have to Check Whether –
- Page number is Already Present or Not.
- There is Empty Location or not.
temp = start; //Temporary Purpose
last = start; //Replacement Purpose
curr = start; //Current Purpose ->-99
We have To insert Total Number of Pages = “Value Specified in Count” so we requires 1 for loop.for(i=0;i< count;i++)
- Check Whether First Page is already Present or not.
res = search(arr[i]);
- If Page is Present then Don’t Take any Action , and Read Next Page.
- But If Page is Present then we have to insert Page in Linked List
Step 4 :
if(res == 0)
if(curr->data == -99)
curr->data = arr[i];
curr = curr->next;
last ->data = arr[i];
last = last->next;
}//end outer if
- If Linked List have Blank Space then First “If Part” gets Executed.
- If Linked List doesn’t have Blank Space then Overwrite on the Oldest Node. [ “last” is used for Keeping Track of Oldest Node , After Overwriting Move “last” one position ahead. ]