The First- in First-out page replacement algorithm operating SYSTEM program in java
FIFO ( FIRST IN FIRST OUT ) PAGE REPLACEMENT ALGORITHM IMPLEMENT BY JAVA
In a operating systems that use paging for memory management, page replacement algorithm are needed to decide which page needed to be replaced when new page comes in. Whenever a new page is referred and not present in memory, page fault occurs and Operating System replaces one of the existing pages with newly needed page. Different page replacement algorithms suggest different ways to decide which page to replace. The target for all algorithms is to reduce number of page faults.
Page Fault – A page fault is a type of interrupt, raised by the hardware when a running program accesses a memory page that is mapped into the virtual address space, but not loaded in physical memory.
Page Replacement Algorithms :
- First In First Out (FIFO) –
This is the simplest page replacement algorithm. In this algorithm, operating system keeps track of all pages in the memory in a queue, oldest page is in the front of the queue. When a page needs to be replaced page in the front of the queue is selected for removal.For example-1, consider page reference string 1, 3, 0, 3, 5, 6 and 3 page slots.Initially all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots —> 3 Page Faults.
when 3 comes, it is already in memory so —> 0 Page Faults.
Then 5 comes, it is not available in memory so it replaces the oldest page slot i.e 1. —>1 Page Fault.
Finally 6 comes, it is also not available in memory so it replaces the oldest page slot i.e 3 —>1 Page Fault. - let take a another example we solve this with help of program given below
- In all our examples, the reference string is
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
3 frame (9 page faults) 4 frame (10 page faults)
LET BEGIN WITH THE PROGRAM(IMPLEMENT IN JAVA)
import java.util.*;
class fifo
{
public static void main(String ar[])
{
int[] a =new int[5];
int[] b =new int[20];
int n,p=0,q=0,m=0,h,k,i,s=0;
String f;
f="fault";
System.out.println("enter the no of pages");
Scanner in =new Scanner(System.in);
n=in.nextInt();
System.out.println("enter the page no");
for(i=0;i<n;i++)
{
b[i]=in.nextInt();
}
for(i=0;i<n;i++)
{
if(p==0)
{
if(q>=3)
{
q=0;
}
a[q]=b[i];
q++;
if(s<3)
{
s=q;
}
}
System.out.print(b[i]);
System.out.print("\t");
for(h=0;h<s;h++)
{
System.out.print("\t"+a[h]);
}
if((p==0)&&(q<=3))
{
System.out.print("\t---->"+f);
m++;
}
System.out.print("\n\n");
p=0;
for(k=0;k<s;k++)
{
if(b[i+1]==a[k])
{
p=1;
}
}
}
System.out.println("total no of faults = "+m);
}
}
WE make sure that the variable will be differ and the value or indexing varry in number
and also we increase the frame size .
pls share this post and help our friend and comment to me for more update contact me at contact us
Comments
Post a Comment