Program-7 - Page Replacement Algorithms
Program-7 - Page Replacement Algorithms
Paging
Paging is a memory management technique used by operating systems to optimize computer
memory usage.
This technique divides the memory into small pages, and each process is allocated a set of
pages. Pages can be swapped in and out of memory as needed, which helps to improve memory
utilization.
Program:
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tRef string\t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("Number of Page Fault is: %d",count);
return 0;
}
Sample Output:
Sample output
Enter no of pages:10
Enter the reference string:7 5 9 4 3 7 9 6 2 1
Enter no of frames:3
7
7 5
7 5 9