10 - b). Design, develop and implement a C/C++/Java program to simulate page replacement technique.
lab10b.c PROGRAM
#include<stdio.h>
int main()
{
int reference_string[10], page_faults = 0, m, n, s, pages, frames;
printf("\nEnter Total Number of Pages:\t");
scanf("%d", &pages);
printf("\nEnter values of Reference String:\n");
for(m = 0; m < pages; m++)
{
printf("Value No. [%d]:\t", m + 1);
scanf("%d", &reference_string[m]);
}
printf("\nEnter Total Number of Frames:\t");
scanf("%d", &frames);
int temp[frames];
for(m = 0; m < frames; m++)
temp[m] = -1;
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(reference_string[m] == temp[n])
{
s++;
page_faults--;
}
}
page_faults++;
if((page_faults <= frames) && (s == 0))
temp[m] = reference_string[m];
else if(s == 0)
temp[(page_faults - 1) % frames] = reference_string[m];
printf("\n");
for(n = 0; n < frames; n++)
printf("%d\t", temp[n]);
}
printf("\nTotal Page Faults:\t%d\n", page_faults);
return 0;
}
lab10b.c PROGRAM
#include<stdio.h>
int main()
{
int reference_string[10], page_faults = 0, m, n, s, pages, frames;
printf("\nEnter Total Number of Pages:\t");
scanf("%d", &pages);
printf("\nEnter values of Reference String:\n");
for(m = 0; m < pages; m++)
{
printf("Value No. [%d]:\t", m + 1);
scanf("%d", &reference_string[m]);
}
printf("\nEnter Total Number of Frames:\t");
scanf("%d", &frames);
int temp[frames];
for(m = 0; m < frames; m++)
temp[m] = -1;
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(reference_string[m] == temp[n])
{
s++;
page_faults--;
}
}
page_faults++;
if((page_faults <= frames) && (s == 0))
temp[m] = reference_string[m];
else if(s == 0)
temp[(page_faults - 1) % frames] = reference_string[m];
printf("\n");
for(n = 0; n < frames; n++)
printf("%d\t", temp[n]);
}
printf("\nTotal Page Faults:\t%d\n", page_faults);
return 0;
}
OUTPUT :( click on image to zoom )
No comments:
Post a Comment