Skip to content

roshhi/pr-sim

Repository files navigation

PRsim

A high-performance, interactive web application for visualizing and analyzing page replacement algorithms in operating systems. Built for students, educators, and systems programmers who need to understand memory management concepts through hands-on simulation.

Table of Contents

Overview

PRsim provides a comprehensive simulation environment for page replacement algorithms, a fundamental concept in operating systems virtual memory management. The application enables real-time visualization of how different algorithms handle page faults, manage memory frames, and make replacement decisions.

Unlike static educational materials, PRsim allows users to observe algorithm behavior dynamically, compare performance metrics across all algorithms simultaneously, and export detailed simulation reports.

Screenshot 2026-02-11 at 12 48 15 PM

Features

Core Simulation

  • Step-by-step execution with detailed state visualization
  • Auto-play mode with configurable playback speed
  • Real-time hit/fault counter and statistics
  • Visual memory frame representation with animated transitions
  • Contextual explanations for each algorithm decision

Algorithm Comparison

  • Side-by-side performance comparison across all seven algorithms
  • Interactive bar charts displaying page faults vs. hits
  • Automatic identification of optimal algorithm for given input
  • Hit rate percentage calculations with visual progress indicators

Learning Mode

  • Interactive game mode for testing algorithm comprehension
  • Score tracking with accuracy metrics
  • Immediate feedback on prediction correctness

Export

  • PDF report generation with dark-themed styling
  • Complete simulation history including frame states
  • Performance summary and algorithm comparison data

Supported Algorithms

Algorithm Description
FIFO First-In-First-Out. Replaces the oldest page in memory. Simple circular queue implementation.
LRU Least Recently Used. Replaces the page that has not been accessed for the longest time. Tracks access recency via timestamps.
Optimal Replaces the page that will not be used for the longest time in the future. Theoretical best-case with FIFO tie-breaking for pages never used again.
MFU Most Frequently Used. Replaces the page with the highest access frequency. Supports configurable tie-breaking (FIFO/LIFO).
LFU Least Frequently Used. Replaces the page with the lowest access frequency. Supports counter reset and tie-breaking strategies.
MRU Most Recently Used. Replaces the most recently accessed page. Useful for specific access patterns.
Clock Second Chance algorithm. Uses reference bits to give pages a second chance before replacement. Circular buffer with pointer-based traversal.

Getting Started

Prerequisites

  • Node.js 18.0+
  • npm 9.0+ or yarn

Installation

git clone <repository-url>
cd pr-sim
npm install

Running the Application

# Development server with hot reload
npm run dev

# Production build
npm run build

# Preview production build
npm run preview

The development server starts at http://localhost:5173 by default.

Usage

Basic Simulation

  1. Enter a reference string (space-separated page numbers):

    7 0 1 2 0 3 0 4 2 3 0 3 2
    
  2. Configure the number of memory frames (1-10)

  3. Select a page replacement algorithm

  4. Click Start Simulation

  5. Navigate through steps using:

    • Next/Previous buttons for manual control
    • Auto-play for continuous execution
    • Reset to restart the simulation

Interpreting Results

  • Green indicators: Page hits (page already in memory)
  • Red indicators: Page faults (page not in memory, requires loading)
  • Frame visualization: Current state of memory with page assignments
  • Explanation panel: Step-by-step reasoning for each operation

Algorithm Comparison

Upon simulation completion, the comparison chart displays:

  • Total page faults per algorithm
  • Total hits per algorithm
  • Best-performing algorithm highlighted

Architecture

src/
├── algorithms/          # Algorithm implementations
│   ├── fifo.js         # FIFO page replacement
│   ├── lru.js          # LRU page replacement
│   ├── optimal.js      # Optimal page replacement
│   ├── mfu.js          # MFU page replacement
│   ├── lfu.js          # LFU page replacement
│   ├── mru.js          # MRU page replacement
│   └── clock.js        # Clock/Second Chance
├── components/          # React UI components
│   ├── LandingPage.jsx # Landing page with documentation
│   ├── InputPanel.jsx  # Configuration form
│   ├── SimulationGrid.jsx # Memory frame visualization
│   ├── ControlPanel.jsx   # Playback controls
│   ├── ChartView.jsx      # Algorithm comparison charts
│   ├── ExplanationBox.jsx # Step explanations
│   ├── Results.jsx        # Simulation results
│   └── GameMode.jsx       # Interactive learning mode
├── utils/
│   └── pdfGenerator.js # PDF export functionality
├── App.jsx              # Application root
├── main.jsx             # Entry point
└── index.css            # Global styles

Algorithm Interface

Each algorithm exports a function with the following signature:

function algorithm(referenceString, numFrames, options?) {
  return {
    history: Array<StepRecord>,
    totalPageFaults: number,
    hitRate: string
  }
}

Configuration Options

MFU/LFU Advanced Options

Option Type Default Description
resetCounter boolean false Reset frequency count when a page is removed
tieBreaking 'FIFO' | 'LIFO' 'FIFO' Strategy for breaking ties when pages have equal frequency

Development

Available Scripts

npm run dev      # Start development server
npm run build    # Create production build
npm run preview  # Preview production build locally
npm run lint     # Run ESLint

Code Quality

The project uses ESLint with React-specific rules. Run linting before commits:

npm run lint

Tech Stack

Category Technology
Framework React 19
Build Tool Vite 7
Styling Tailwind CSS 3
Animations Framer Motion
Charts Recharts
PDF Generation jsPDF
Smooth Scrolling Lenis
Icons Lucide React

License

MIT License. See LICENSE for details.


Author: Muhammad Ahmad

About

A web application for visualizing and analyzing page replacement algorithms in operating systems.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors