Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory. This scheme permits the physical address space of a process to be non – contiguous. Given below is one of the page replacement algorithm program, you are to first identify which algorithm (FIFO, Optimal Page Replacement, Least frequently used) is implemented in given c-code. Please consider following reference string for this page replacement algorithm (1,2,3 5,1,3,4,5,6,1,5,3,2) with 4 page/frame size. There are some errors in this program, you have to correct it first, and then explain compiled output with each miss or hit condition. #include void main() { int pos,c,m,maxi,i,k,nf,count,j=0,pf=0,np=0; printf("enter no. of pages"); scanf("%d",&np); int s[np]; printf("Enter pages sequence :\n"); for(i=0;i %d\n",pf); } else { for(j=0;jmaxi){ maxi=q1[m]; pos=m;} q[pos]=s[i];pf++; for(m=0;m %d\n",pf); } }printf("the total no. of page faults are: %d",pf); }
Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory. This scheme permits the physical address space of a process to be non – contiguous.
Given below is one of the page replacement
There are some errors in this program, you have to correct it first, and then explain compiled output with each miss or hit condition.
|
|
|
#include <stdio.h> |
void main() |
|
{ |
|
int pos,c,m,maxi,i,k,nf,count,j=0,pf=0,np=0; |
|
printf("enter no. of pages"); |
|
scanf("%d",&np); |
|
int s[np]; |
|
printf("Enter pages sequence :\n"); |
|
for(i=0;i<np;i++) |
|
scanf("%d",&s[i]); |
|
printf("enter the no. of frames"); |
|
scanf("%d",&nf); |
|
int q[nf],q1[nf]; |
|
for(i=0;i<nf;i++) |
|
q[i]=-1; |
|
for(i=0;i<np;i++) |
|
{maxi=0; |
|
for(m=0;m<nf;m++) |
|
q1[m]=-1; |
|
c=0; |
|
for(k=0,k<nf;k++) |
|
if(s[i]==q[k]) |
|
c++; |
|
if(c==0) |
|
{ |
|
if(q[nf-1]==-1) |
|
{ |
|
q[j]=s[i]; |
|
pf++; |
|
j++; |
|
for(k=0;k<nf;k++) |
|
printf("%d\t",q[k]); |
|
printf("-> %d\n",pf); |
|
} |
|
else { |
|
for(j=0;j<nf;i++){ |
|
for(m=i+1,count=0;m<np;m++,count++) |
|
if(q[j]==s[m] && q1[j]==-1) |
|
q1[j]=count; |
|
if(q1[j]==-1){ |
|
for(m=0;m<i;m++,count++) |
|
if(q[j]==s[m] && q1[j]==-1) |
|
q1[j]=count; |
|
} |
|
} |
|
for(m=0;m<nf;m++) |
|
if(q1[m]>maxi){ |
|
maxi=q1[m]; |
|
pos=m;} |
|
q[pos]=s[i];pf++; |
|
for(m=0;m<nf;m++) |
|
printf("%d ",q[m]); |
|
printf("-> %d\n",pf); |
|
|
|
|
|
|
|
} |
|
}printf("the total no. of page faults are: %d",pf); |
|
|
|
} |
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)