OS 12 c
OS 12 c
faults++;
found = 1;
break;
}
}
}
// If no empty frame and page not found — Replace Optimal
if (!found) {
int future[10];
for (j = 0; j < f; j++) {
future[j] = -1;
for (k = i + 1; k < n; k++) {
if (frames[j] == pages[k]) {
future[j] = k;
break;
}
}
}
// Find the page not used for longest time
max = -1;
pos = -1;
for (j = 0; j < f; j++) {
if (future[j] == -1) {
pos = j;
break;
} else if (future[j] > max) {
max = future[j];
pos = j;
}
}
Sprno:9223
frames[pos] = pages[i];
faults++;
}
// Display frames
printf("%d\t", pages[i]);
for (j = 0; j < f; j++) {
if (frames[j] == -1)
printf("- ");
else
printf("%d ", frames[j]);
}
printf("\n");
}
printf("\nTotal Page Faults = %d\n", faults);
return 0;
}
OUTPUT:
Enter number of pages: 5
Enter page reference string: 1 2 3 2 4
Enter number of frames: 3
Page Frames
1 1--
2 12-
3 123
2 123
4 423
Total Page Faults = 4