Question
Write a program that simulates the FIFO and LRU page-replacement algorithms. Your program should accept four command-line arguments specifying the page size, the total virtual
Write a program that simulates the FIFO and LRU page-replacement algorithms. Your program should accept four command-line arguments specifying the page size, the total virtual memory size, the page-replacement algorithm to use, and the number of frames allocated. The page and virtual memory sizes should be specified by their binary logs. Thus, the following command would simulate a page size of 1KB and a virtual memory size of 64KB, using LRU page-replacement with 8 frames allocated:
> ./simulate-paging 10 16 LRU 8
Your program should read lines from standard input, each containing a hexadecimal number representing the virtual address of a memory reference. With each memory reference, your program should update an internal page table, keeping track of the number of page faults generated using pure demand paging. Your program should also maintain any other data structures necessary to implement the two page-replacement algorithms. Your program should terminate upon encountering EOF. It should then print the total number of page faults and exit.
To assist with testing, two sample input files are available on iLearn. sample_references.txt contains a list of virtual addresses that when used with a page size of 256 bytes correspond to the reference string used during lecture and in the book. ( Google docs link to file: https://drive.google.com/file/d/1QEat_sPYrRaExZOoXcT7syWCWq__JX7h/view?usp=sharing )
For example:
> ./simulate_paging 8 12 LRU 3 < sample_references.txt
12 page faults
belady_references.txt contains a list of virtual addresses that when used with a page size of 16KB corresponds to the reference string that demonstrates Belady's anomaly (Google docs link to file: https://drive.google.com/file/d/1yUzinym2fmAHs9aBorRiApWTkAV6hanF/view ) :
> ./simulate_paging 16 20 FIFO 3 < belady_references.txt
9 page faults
> ./simulate_paging 16 20 FIFO 4 < belady_references.txt
10 page faults
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started