| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This project implements and compares Page Replacement Algorithms as part of an Operating Systems Problem-Based Learning (PBL) assignment. It demonstrates how different strategies handle memory management when pages are requested by a process but limited frames are available.
page-replacement-algorithms-analysis/
│
├── docs/ # Documentation folder (reports, diagrams, extended notes)
│
├── src/ # Source code folder
│ ├── algorithms.h # Header file declaring prototypes for all algorithms
│ ├── fifo.c # FIFO algorithm implementation
│ ├── fifo.o # Compiled object file for FIFO
│ ├── lfu.c # LFU algorithm implementation
│ ├── lfu.o # Compiled object file for LFU
│ ├── lru.c # LRU algorithm implementation
│ ├── lru.o # Compiled object file for LRU
│ ├── optimal.c # Optimal algorithm implementation
│ ├── optimal.o # Compiled object file for Optimal
│ ├── utils.c # Utility functions (printing, helpers, frequency tracking)
│ ├── utils.h # Header file for utility functions
│ ├── utils.o # Compiled object file for utils
│ ├── main.c # Entry point: handles input, calls algorithms, prints results
│ ├── main.o # Compiled object file for main
│ ├── Makefile # Cross-platform build script (Windows + Linux)
│ ├── page_replacement # Linux executable (built via `make`)
│ └── page_replacement.exe # Windows executable (built via `mingw32-make`)
│
└── README.md # Project documentation (overview, usage, algorithms, contributors)
To build and run this project successfully, ensure the following prerequisites are installed and configured:
sudo pacman -S gcc # Arch Linux
sudo apt-get install gcc # Ubuntu/Debiansudo pacman -S make # Arch Linux
sudo apt-get install make # Ubuntu/Debianpacman -Syupacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-makegit clone https://github.com/Code-Crew-Nexus/page-replacement-algorithms-analysis.git
cd page-replacement-algorithms-analysis/srcThis project uses a cross-platform Makefile that works on both Windows 11 (MinGW/MSYS2) and Linux (Arch, Ubuntu, etc.).
make clean
make
make runmingw32-make clean
mingw32-make
mingw32-make runThe Makefile automatically detects the OS and builds the correct executable (page_replacement on Linux, page_replacement.exe on Windows).
The program simulates page replacement algorithms by:
| Algorithm | Strategy | Strength | Weakness |
|---|---|---|---|
| FIFO | Oldest page replaced | Simple, easy to implement | May evict frequently used pages |
| LRU | Least recently used | Good approximation of optimal | Requires tracking usage history |
| Optimal | Furthest future use | Lowest possible faults | Not implementable in real systems (needs future knowledge) |
| LFU | Least frequently used | Keeps popular pages | May evict recent but important pages |
Input:
Enter number of pages in reference string: 12 Enter the reference string (space-separated): 1 2 3 4 1 2 5 1 2 3 4 5 Enter number of frames: 3
Output:
---- FIFO Simulation ---- Page Frames Result 1 1 - - FAULT 2 1 2 - FAULT 3 1 2 3 FAULT 4 4 2 3 FAULT 1 4 1 3 FAULT 2 4 1 2 FAULT 5 5 1 2 FAULT 1 5 1 2 HIT 2 5 1 2 HIT 3 5 3 2 FAULT 4 5 3 4 FAULT 5 5 3 4 HIT Total Page Faults (FIFO): 9 ---- LRU Simulation ---- Page Frames Result 1 1 - - FAULT 2 1 2 - FAULT 3 1 2 3 FAULT 4 4 2 3 FAULT 1 4 1 3 FAULT 2 4 1 2 FAULT 5 5 1 2 FAULT 1 5 1 2 HIT 2 5 1 2 HIT 3 3 1 2 FAULT 4 3 4 2 FAULT 5 3 4 5 FAULT Total Page Faults (LRU): 10 --- Optimal Simulation --- Page Frames Result 1 1 - - FAULT 2 1 2 - FAULT 3 1 2 3 FAULT 4 1 2 4 FAULT 1 1 2 4 HIT 2 1 2 4 HIT 5 1 2 5 FAULT 1 1 2 5 HIT 2 1 2 5 HIT 3 3 2 5 FAULT 4 4 2 5 FAULT 5 4 2 5 HIT Total Page Faults (Optimal): 7 ---- LFU Simulation ---- Page Frames Result 1 1 - - FAULT 2 1 2 - FAULT 3 1 2 3 FAULT 4 4 2 3 FAULT 1 1 2 3 FAULT 2 1 2 3 HIT 5 5 2 3 FAULT 1 1 2 3 FAULT 2 1 2 3 HIT 3 1 2 3 HIT 4 4 2 3 FAULT 5 5 2 3 FAULT Total Page Faults (LFU): 9
Output (summary):
=== Final Page Replacement Analysis === FIFO Page Faults : 9 LRU Page Faults : 10 Optimal Page Faults: 7 LFU Page Faults : 9
This project provides a comprehensive analysis of Page Replacement Algorithms — FIFO, LRU, Optimal, and LFU — by simulating their behavior on given reference strings and comparing their performance. It demonstrates how different strategies handle page faults when memory frames are limited, highlighting the trade‑offs between simplicity, efficiency, and practicality in operating system design.
The project is designed with a cross‑platform Makefile, ensuring seamless compilation and execution on both Windows 11 (MinGW/MSYS2) and Linux (Arch/Ubuntu). With clear documentation, structured source code, and sample input/output demonstrations, this repository serves as both an academic resource and a practical tool for understanding memory management strategies in operating systems.
Future contributors welcome! Fork the repo, submit pull requests, and help improve the project.
| Back | FazBrowse Home | New Git URL |