0% found this document useful (0 votes)
13 views3 pages

12A To Implement The Various Page Replacement Algorithm-Last in First Out Program

The document contains a C program that implements the Last In First Out (LIFO) page replacement algorithm. It prompts the user to enter the number of frames, pages, and a page reference string, then simulates the page replacement process while tracking page faults. The output demonstrates the frames' state after each page reference and the total number of page faults encountered.

Uploaded by

jayaprakash9223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

12A To Implement The Various Page Replacement Algorithm-Last in First Out Program

The document contains a C program that implements the Last In First Out (LIFO) page replacement algorithm. It prompts the user to enter the number of frames, pages, and a page reference string, then simulates the page replacement process while tracking page faults. The output demonstrates the frames' state after each page reference and the total number of page faults encountered.

Uploaded by

jayaprakash9223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Sprno:9223

12A TO IMPLEMENT THE VARIOUS PAGE REPLACEMENT ALGORITHM-


LAST IN FIRST OUT
PROGRAM:
#include <stdio.h>
int main() {
int frames, pages, i, j, k, faults = 0;
int found, top = 0;
printf("Enter number of frames: ");
scanf("%d", &frames);
printf("Enter number of pages: ");
scanf("%d", &pages);
int pageSeq[pages], frame[frames];
printf("Enter page reference string: ");
for (i = 0; i < pages; i++)
scanf("%d", &pageSeq[i]);
// Initialize frames
for (i = 0; i < frames; i++)
frame[i] = -1;
printf("\nPage\tFrames\n");
for (i = 0; i < pages; i++) {
found = 0;
// Check if page is already in a frame
for (j = 0; j < frames; j++) {
if (frame[j] == pageSeq[i]) {
found = 1;
break;
}
}
if (!found) {
// Replace the most recently added page (LIFO strategy)
Sprno:9223

top = (top == 0) ? frames - 1 : top - 1;


frame[top] = pageSeq[i];
faults++;
printf("%d\t", pageSeq[i]);
for (k = 0; k < frames; k++) {
if (frame[k] == -1)
printf("- ");
else
printf("%d ", frame[k]);
}
printf("\n");
} else {
printf("%d\tNo page fault\n", pageSeq[i]);
}
}
printf("\nTotal Page Faults = %d\n", faults);
return 0;
}
OUTPUT:
Enter number of frames: 3
Enter number of pages: 7
Enter page reference string: 1 3 0 3 5 6 3
Page Frames
1 --1
3 -31
0 031
3 No page fault
5 531
6 631
3 No page fault Total Page Faults = 5
Sprno:9223

You might also like