C Program FIFO Page Replacement Policy : Explanation
Program : [ Click Here ]
Step 1 : Accept Given Data .
- Frame Number : fno
- Number of Pages : count
- Actual Pages : arr[100]
void accept()
{
int i;
printf("nEnter the number of Frames : ");
scanf("%d",&fno);
printf("nEnter the number of Pages : ");
scanf("%d",&count);
printf("nEnter the Page No : ");
for(i=0;i< count;i++)
scanf("%d",&arr[i]);
}
Step 2 :
- Now we have Pages and Frame Size.
- Total Number of Pages is Given by Variable : “Count“.
Logic :
- 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 ->-99We 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)
{
fault++;
if(curr->data == -99)
{
curr->data = arr[i];
curr = curr->next;
}
else
{
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. ]