You are to write a Java program that calculates the number o

You are to write a Java program that calculates the number of page faults using three different page replacement algorithms. - The program should accept 2 command line arguments, a file name and the number of frames. You would run the program like: java hw2 inputl.txt 3 - The program should open the file (the first argument) and read in the page reference string. Two example files have been provided (inputl.txt and input2.txt). The file will have one line of data consisting of comma separated numbers (there won\'t be any negative values). - The program should then calculate and output the number of page faults for the optimal, FIFO, and LRU page replacement algorithms. - The number of frames must be dynamic (since it is given as an argument) but will be at least 1. So from 1 to some very large number, it should still work. Do NOT hard code this value.

Solution

OUTPUT :
2 -1 -1
2 3 -1
2 3 -1
2 3 1
5 3 1
5 2 1
5 2 4
5 2 4
3 2 4
3 2 4
3 5 4
3 5 2

Number of page faults : 6

  #include<stdio.h>  #include<conio.h>  int fr[3];  void main()  {  void display();  int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};  int flag1=0,flag2=0,pf=0,frsize=3,top=0;  clrscr();  for(i=0;i<3;i++)  {  fr[i]=-1;  }  for(j=0;j<12;j++)  {  flag1=0;  flag2=0;  for(i=0;i<12;i++)  {  if(fr[i]==page[j])  {  flag1=1;  flag2=1;  break;  }  }  if(flag1==0)  {  for(i=0;i<frsize;i++)  {  if(fr[i]==-1)  {  fr[i]=page[j];  flag2=1;  break;  }  }  }  if(flag2==0)  {  fr[top]=page[j];  top++;  pf++;  if(top>=frsize)  top=0;  }  display();  }  printf(\"Number of page faults  : %d \",pf);  getch();  }  void display()  {  int i;  printf(\"\ \");  for(i=0;i<3;i++)  printf(\"%d\\t\",fr[i]);  }  
 You are to write a Java program that calculates the number of page faults using three different page replacement algorithms. - The program should accept 2 comm

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site