Simulator of Page Replace Management
Visualizing page replacement algorithms includes (1) Least Recently Used (LRU) (2) Optimal (OPT) (3) First in and First out (FIFO) (4) Clocks (2) Second Chance. Development Language: c .
1.LRU
#include<stdio.h>
int RS[30],n,nf;
struct frame
{
int value;
int pos;
} Frame[10];
main()
{
int i,j,k=0,check=0,pf=0,x,y,q,max=321;
printf("Enter the frame size:");
scanf("%d",&nf);
printf("Enter the size of reference string:");
scanf("%d",&n);
printf("Enter the reference string:\n");
for(i=0;i<n;i++)
scanf("%d",&RS[i]);
for(i=0;i<nf;i++)
Frame[i].value=-1;
for(i=0;i<n;i++)
{
for(j=0;j<nf;j++)
{
if(RS[i]==Frame[j].value)
check=1;
}
if(check==0)
{
pf++;
if(k<nf)
{
Frame[k].value=RS[i];
k++;
}
else
{
for(x=0;x<nf;x++)
{
for(y=i-1;y>=0;y--)
{
if(Frame[x].value==RS[y])
{
Frame[x].pos=y;
break;
}
}
}
for(q=0;q<nf;q++)
{
if(Frame[q].pos<max)
max=Frame[q].pos;
}
for(q=0;q<nf;q++)
{
if(Frame[q].value==RS[max])
Frame[q].value=RS[i];
}
max=321;
}
}
check=0;
}
printf("\nNumber of page faults:%d",pf);
}
2.Optimal:
#include<stdio.h>
//int page[30],n,nf;
struct frame
{
int value;
int pos;
} Frame[10];
main()
{
int
i,j,k=0,n,nf,check=0,pf=0,x,y,q,max=-9999,val;
printf("Enter the frame size:");
scanf("%d",&nf);
printf("Enter the size of reference string:");
scanf("%d",&n);
int page[n];
printf("Enter the reference string:\n");
for(i=0;i<n;i++)
scanf("%d",&page[i]);
for(i=0;i<nf;i++)
Frame[i].value=-1;
for(i=0;i<n;i++)
{
check=0;
for(j=0;j<nf;j++)
{
if(page[i]==Frame[j].value)
check=1;
}
if(check==0)
{
pf++;
if(k<nf)
{
Frame[k].value=page[i];
k++;
}
else
{
for(x=0;x<nf;x++)
{
for(y=i+1;y<n;y++)
{
if(Frame[x].value==page[y]) //It will checkes the last position of
page while increment the j value
{
Frame[x].pos=y; // this is for position of the
page
break;
}
}
if(Frame[x].pos<i) // if
the page is not found in future then the page is replaced in that
frame in below code
Frame[x].pos=9999;
}
for(x=0;x<nf;x++)
{
if(Frame[x].pos>max)
//this is for to check max position of each frame
{
max=Frame[x].pos;
val=Frame[x].value;
Frame[x].pos=i+1; // this is used to check the remaining frame
position which is having less posi than max
}
}
for(x=0;x<nf;x++) // in this case the
remaining pages are replaced which are not repeated
{
if(Frame[x].value==val)
//this is used to check for max posi and current frames are same
are not
Frame[x].value=page[i];
}
}
}
}
printf("\nNumber of page faults:%d",pf);
}
3.FIFO:
#include<stdio.h>
main()
{
int m,n,i,j,k,f=0,old=0;
printf("Enter no of frames:");
scanf("%d",&m);
printf("Enter no of pages:");
scanf("%d",&n);
int frames[m],pages[n];
for(i=0;i<m;i++)
{
frames[i]=-1;
}
for(i=0;i<n;i++)
{
scanf("%d",&pages[i]);
}
for(i=0;i<n;i++)
{
k=0;
for(j=0;j<m;j++)
{
if(pages[i]==frames[j])
{
k=1;
break;
}
}
if(k==0)
{
frames[old]
=pages[i];
old++;
f++;
old=old%m;
}
printf("\n");
for(j=0;j<m;j++)
{
printf("%d\t",frames[j]);
}
printf("\t\t\t\t%d",f);
}
}
4.clock:
#include<stdio.h>
int main()
{
int n,p[100],f[10],ava,hit=0,usebit[10],i,j;
printf("enter the length of the Reference string: ");
scanf("%d",&n);
printf("enter the reference string: \n");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
for(i=0;i<n;i++)
{
ava=0;
// found
for(j=0;j<3;j++)
{
if(p[i]==f[j])
{
ava=1;
hit++;
usebit[j]=1;
break;
}
}
//search for usebit 0
if(ava==0)
{
for(j=0;j<3;j++)
{
if(usebit[j]==0)
{
f[j]=p[i];
usebit[j]=1;
ava=1;
break;
}
}
}
// fifo
if(ava==0)
{
for(j=0;j<3;j++)
usebit[j]=0;
}
f[0]=p[i];
usebit[0]=1;
}
printf("The number of Hits: %d",hit);
return 0;
}
Simulator of Page Replace Management Visualizing page replacement algorithms includes (1) Least Recently Used (LRU) (2)...
Simulator of Page Replace Management Visualizing page replacement algorithms includes (1) Least Recently Used (LRU) (2) Optimal (OPT) (3) First in and First out (FIFO) (4) Clocks (2) Second Chance. Development Language: c .
Apply the (1) FIFO, (2) LRU, and (3) optimal (OPT) replacement algorithms for the following page-reference strings: • 2, 6, 9, 2, 4, 2, 1, 7, 3, 0, 5, 2, 1, 2, 9, 5, 7, 3, 8, 5 • 0, 6, 3, 0, 2, 6, 3, 5, 2, 4, 1, 3, 0, 6, 1, 4, 2, 3, 5, 7 • 3, 1, 4, 2, 5, 4, 1, 3, 5, 2, 0, 1, 1, 0, 2, 3, 4, 5, 0, 1 • 4, 2, 1,...
find the number of page faults that occur during FIFO, OPT, LRU cafe replacement with 4 frames. Mention the number of page faults after each replacement strategy. If you find any ties replace the page with the highest numeric value. Here is the reference of string pages. 9 2 6 9 6 0 5 5 6 0 3 1 6 1 0
Write a program that implements the FIFO, Optimal, MFU, and LRU page-replacement algorithms. Given a page-reference string, where page numbers range from 0 to 9, apply the page-reference string to each algorithm, and output the number of page faults incurred by each algorithm. Write your code so that the number of page frames in the page table can vary from 1 to 10. 1.0 Functional Requirements 1.1: Your program shall be run with the following: ./a.out Example: ./a.out datafile.txt 1.2:...
Least Recently Used (LRU) is the most favorable replacement policy for direct mapped caches in MIPS architectures. True False L A Moving to another question will save this response. esc BO F2 FA # 3 $ % 5 2 4 6 w
Question 7 30 pts Consider the following page reference string: {1,2,3,4,1,5,6,2,1,2,3,7,6,3} Assume that the system has 4 page frames allocated to these 7 pages. Follow the page placement and replacement using the following three replacement algorithms: • LRU replacement • FIFO replacement • Optimal replacement How many page faults will occur for these three algorithms? Assume that all frames are initially empty, so your first unique pages will all cost one fault each USE ENCLOSED TABLES! Show all calculations in...
Name Olbinna COSC414/514 Quiz3 (1) Suppose a computer has 4 physical pages, and a process references its virtual pages (page o through page 7) in the following order: 021354637473355311172341 Also suppose the first four pages have been loaded in the physical memory as the following figure: Frame 0 Frame 1 Frame 2 Frame 3 a. Suppose the kernel uses First-In-First-Out (FIFO) page replacement algorithm. How many page faults would the process have? Which page references are page faults? b. Suppose...
Consider the following virtual page reference sequence: page 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3. This indicates that these particular pages need to be accessed by the computer in the order shown. Consider each of the following 4 algorithm-frame combinations: LRU with 3 frames FIFO with 3 frames LRU with 4 frames FIFO with 4 frames . For each of the 4 combinations, below, move from left to right as the virtual page numbers are...
Consider the following page reference string for a specific process: 7, 2, 3, 1, 2, 5, 3, 4, 6, 7, 7, 1, 0, 5, 4, 6, 2, 3, 0, 1 Assuming demand paging with 3 frames, determine the page fault rate for each of the following page replacement algorithms: a. LRU replacement b. FIFO replacement c. Optimal replacement
Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6. How many page faults would occur for the following replacement algorithms, assuming one, two, three, four, five, six, or seven frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each. • LRU replacement • FIFO replacement • Optimal replacement