Skip to main content

Posts

Showing posts with the label page replacement

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[++...

Write the simulation program for demand paging and show the page scheduling and total number of page faults according to MFU page replacement algorithm. Assume the memory of n frames.

Write the simulation program for demand paging and show the page scheduling and total number of page faults according to MFU page replacement algorithm. Assume the memory of n frames. Program: #include <stdio.h> #include <stdlib.h> int stack[5], x,f,al[10],flag; void selectPage(int s){ int i,j; for(i=0;i<x;i++){ if(stack[i]==s){ for(j=i;j<x;j++){ stack[j]=stack[j+1]; } } } stack[x]=s; } int searchPage(int s){ int i; for(i=0;i<f;i++){ if(al[i]==s){ return i; } } return -1; } void main(){ setbuf(stdout,NULL); int i,j,pg[50],tp,pf; printf("\nEnter the number of frames:"); scanf("%d",&f); printf("\nEnter the total pages:"); scanf("%d",&tp); printf("\nEnter the page string:"); for(i=0;i<tp;i++){ scanf("%d",&pg[i]); } pf=0; x=-1; flag=-1; for(i=0;flag!=f;i++){ if(searchPage(pg[i])==-1){ pf++; stack[++x]=pg[i]; al[++flag]=pg[i]; }else...