Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames.
Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames.
Program:
#include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int f, tp ,al[50][50]={-1, -1}, i,j,pg[50],pf,x,queue[50]; printf("\nEnter total number of frames:"); scanf("%d",&f); printf("\nEnter total number of pages:"); scanf("%d",&tp); printf("\nEnter page string:"); for(i=0;i<tp;i++){ scanf("%d",&pg[i]); } pf=0; for(i=0;i<tp;i++){ for(j=0;j<f;j++){ if(al[j][i]==pg[i]){ break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==-1){ al[j][i]=pg[i]; queue[++x]=pg[i]; pf++; break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==queue[x]){ al[j][i]=pg[i]; pf++; x--; } } } } else{ queue[++x]=pg[i]; } } printf("\nTotal page faults are:%d\n",pf); for(j=0;j<f;j++){ printf(" %d",al[i][0]); } printf("\n"); for(j=0;j<f;j++){ printf(" %d",al[i][1]); } printf("\n"); for(j=0;j<f;j++){ printf(" %d",al[i][2]); } }
Comments
Post a Comment