8FIFO
8FIFO
#include<stdio.h> #include<conio.h> int c,p,i,j,sz[20],frame[20],t=0,x; int found(int x); int freefound(); main() { static int pf,k; clrscr(); printf("Enter no.of frames"); scanf("%d",&p); for(i=0;i<p;i++) frame[i]=-1; printf("Enter sizes of pages"); for(i=0;;i++) { scanf("%d",&sz[i]); if(sz[i]==-1) break; c=c+1; } for(i=0;i<c;i++) { if(found(sz[i])) continue; x=freefound(); if(x!=-1) frame[x]=sz[i]; else { frame[t]=sz[i]; t=(t+1)%p; } pf=pf+1; printf("\nThe values present in frame= "); for(k=0;k<p;k++) if(frame[k]!=-1) printf("%d",frame[k]); } printf("\nThe total no.of page faults are%d",pf); printf("Enter the value"); scanf("%d",&i); } int found(int x) { int j; for(j=0;j<p;j++) if(frame[j]==x)
return 1; return 0; } int freefound() { int i; for(i=0;i<p;i++) if(frame[i]==-1) return i; return -1; } RESULT: Input:Enter no.of frames 3 Enter sizes of pages 2 3 2 1 5 2 4 5 3 2 5 2 -1 Output: The values present in frame=2 The values present in frame=2 The values present in frame=2 The values present in frame=5 The values present in frame=5 The values present in frame=5 The values present in frame=3 The values present in frame=3 The values present in frame=3 The total number of page faults
3 3 3 2 2 2 5 5 are
1 1 1 4 4 4 2 9