$24
Q1. In this assignment you will test the efficacy of various virtual memory paging schemes. You will implement paging scheme: a) Least Recently Used (LRU), b) Least Frequently Used (LFU), c) Optimal. Your program should read the sequence of page accesses from the file "pages.txt" ,emulate the paging schemes, and then print a short report detailing the performance statistics.
Input Format
The file is comprised of a sequence of "tries". Each try consists of a line containing a single integer, f , representing the number of frames of memory in the operating system, and then, in subsequent lines, any number of integers, 0-99, representing page numbers. The sequence of integers is a "reference string"--a sequence of page requests. The reference string shall be terminated by a value of -1 (which does not represent a page number.)
Sample Input:
3
1 2 3 4 3 4 2 3 5 6 4 2 1 2 -1
4
1 2 3 4 2 7 5 1 1 6 4 7 2 1 2 5 -1
Output
For each "try" your program should print a table detailing the page replacements affected by each of the four paging methods. Be sure that you properly handle the printing of these tables when the length of the reference string is large enough that the table is wider than the page. After printing the paging tables, your program should print a table detailing the number of page faults affected by the paging schemes. Below is the output that should result from the sample input.
Example output:
LRU:
1 2 3 4 3 4 2 3 5 6 4 2 1 2
__________________________________________
1
1
1
4
5
5
5
2
2
0
2
2
2
2
6
6
6
1
0
0
3
3
3
3
4
4
4
LFU:
1 2 3 4 3 4 2 3 5 6 4 2 1 2
__________________________________________
1
1
1
4
4
6
6
6
1
0
2
2
2
5
5
5
2
2
0
0
3
3
3
3
4
4
4
Optimal:
1 2 3 4 3 4 2 3 5 6 4 2 1 2
__________________________________________
1
1
1
4
4
4
1
0
2
2
2
2
2
2
0
0
3
3
5
6
6