FIFO is the simplest technique for replacing pages in a frame. It decides when a page fault occurs then which frames are to be replaced. Create a program to counts the number of page fault occurs when an input reference string is given. The input contains integer values for a number of pages in a queue, sequence of reference strings and frame size. The output should display the total number of page faults.
Note: Text in Bold corresponds to the input
Sample Input and Output
Enter No. of Pages:
6
Enter values of Reference String :
1
2
2
3
1
4
Enter no. of frames:
3
Total Page Faults 4
Answer:
#include<stdio.h> int main() { int i,j,n,a[30],no,k,av,count=0,frame[10]; printf("Enter No. of Pages:\n"); scanf("%d",&n); printf("Enter values of Reference String :\n"); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("Enter no. of frames:\n"); scanf("%d",&no); for(i=0;i<no;i++) { frame[i]=-1; } for(i=0;i<n;i++) { av=0; for(k=0;k<no;k++) if(frame[k]==a[i]) av=1; if(av==0) { frame[j]=a[i]; j=(j+1)%no; count++; } } printf("Total Page Faults %d",count); return 0; }
0 Comments