Skip to content

rimasulz/OS_mini_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project: Page Replacement Simulator Student Name: Tahrima Sultana Student ID: 110069971 Date: April 15, 2026

  1. Description

    This program simulates three page replacement algorithms including:

    • FIFO (First in, first out): Replaces the oldest page in the frames regardless of access history.

    • LRU (Least recently used): Tracks the access history and replaces the page that hasn't been used for the longest period.

    • Clock (Second Chance): Uses a reference bit to give recently accessed pages a second chance before replacement.

  2. Implementation:

    • Language: Python3
    • Libraries: json, sys
  3. HOW TO RUN

    The program accepts an input JSON file and produces an output JSON file via command-line arguments.

    • Input Syntax:

      python3 main.py <input_file.json> > <output_file.json>

    • Input Format:

      The input file must be a JSON object containing:

        - algorithm: "FIFO", "LRU", or "Clock"
        - frames: Number of available physical memory frames (Integer)
        references: List of page reference strings (Array of Integers)
        - trace: Boolean to toggle step-by-step memory snapshots.
      
        Ex.
            {
                "algorithm": "Clock",
                "frames": 3,
                "references": [7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2],
                "trace": true
            }
      
  4. Explanation

    Design Decisions:

    • FIFO and LRU: Both algorithms were implemented using a queue (python list) structure. By maintaining the "oldest" or "least recently used" page at index 0, it made it easy to replace. For LRU, a "hit" triggers a repositioning of the page to the end of the list to reset its age priority.

    • Clock (Second-Chance): This was implemented using a circular buffer approach. Instead of a simple list of integers, the frames are stored as a list of lists: [page_number, reference_bit]. A pointer was used to track the clock. This design was chosen because it allows the pointer to cycle through memory without the overhead of shifting elements in the list, providing a more hardware-accurate simulation.

    Tie-Breaking Policy:

    • Sequential Eviction: In all three algorithms, since pages are added to the list or circular buffer in the order they arrive, the page at the current pointer (Clock) or index 0 (FIFO/LRU) is the "earliest" candidate for eviction.

    • Smallest Page Number: In the case that multiple pages might technically share a replacement priority, the program defaults to the page occupying the lower index in the frame list.

    AI Usage:

    AI, specifically Gemini, was used to validate, or if need be, alter, personally crafted algorithms in pseudocode, and assist in correctness of translating such to Python3 syntax. It was also used to generate sample inputs and outputs of test cases to compare for successful program running.

(github repo): https://github.com/rimasulz/OS_mini_project

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages