OSL Pract 5
OSL Pract 5
OSL Pract 5
5
PAGE REPLACEMENT ALGORITHMS
AIM: Write a program to implement page Replacement strategies -
a) FIFO
b) LRU
c) OPTIMAL
DESCRIPTION:
Demand Paging
The Demand Paging is a condition which is occurred in the Virtual
Memory.
We know that the pages of the process are stored in secondary
memory.
The page is brought to the main memory when required. We do not
know when this requirement is going to occur. So, the pages are
After filling up of the frames, the next page in the waiting queue tries to
enter the frame. If the frame is present then, no problem is occurred.
Because of the page which is to be searched is already present in the
allocated frames.
Page Hit.
If the page to be searched is found among the frames then, this process is
known as Page Hit.
Page Fault
If the page to be searched is not found among the frames then, this process
is known as Page Fault.
Example:
The Least Recently Used (LRU) Page Replacement Algorithms works on a certain
principle. The principle is:
Replace the page with the page which is less dimension of time recently used page in
the past.
Example:
Suppose the Reference String is:
6, 1, 1, 2, 0, 3, 4, 6, 0
The pages with page numbers 6, 1, 2 are in the frames occupying the frames.
Now, we need to travel back into the past to check which page can be replaced.
Let us understand this Least Recently Used (LRU) Page Replacement Algorithm
working with the help of an example.
Example:
Reference String:
The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 35 = 65%
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
int fr[3];
void main()
{
void display();
int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3];
int index,k,l,flag1=0,flag2=0,pf=0,frsize=3;
ALGORTHIM:
1. Start Program
2. Read Number Of Pages And Frames
3.Read Each Page Value
4. Search For Page In The Frames
5.If Not Available Allocate Free Frame
6. If No Frames Is Free Repalce The Page With The Page That Is
Leastly Used
7.Print Page Number Of Page Faults
8.Stop process.
Example:
Example:
Points to Remember
Reference String:
The Ratio of Page Hit to the Page Fault = 8 : 12 - - - > 2 : 3 - - - > 0.66
The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 40 = 60%
SOURCE CODE:
/*
Program to simulate optimal page replacement */
#include<stdio.h>
#include<conio.h>
int fr[3], n, m;
void
display();
void main()
{
int i,j,page[20],fs[10];