Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

Concurrent OS Simulator

This project is a multithreaded operating-system simulator implemented in Java. The simulation advances through a logical tick-based clock and models core operating-system concepts, including CPU scheduling, virtual memory, disk I/O, resource management, and deadlock recovery.

Features

  • Four main simulator threads
  • Tick-based logical system clock
  • CPU scheduler as the only clock owner
  • Multilevel CPU scheduling
    • System queue using FCFS
    • Interactive queue using Round Robin
    • Background queue using SRTF
    • Fixed-priority scheduling between queues
    • Aging to reduce starvation
  • Context-switch overhead
  • Virtual memory with page tables and a TLB
  • Page-fault handling through disk I/O
  • Two page-replacement policies
    • FIFO
    • LRU
  • READ and WRITE memory accesses
  • Dirty-page tracking
  • Dirty-page write-back before eviction
  • Resource allocation and release
  • Deadlock detection and recovery
  • Per-tick system reports
  • Final simulation statistics

Project Structure

src/os/simulator/
├── app/          # Application entry point
├── concurrency/  # Shared synchronization utilities
├── core/         # Logical system clock
├── io/           # Disk I/O handling
├── memory/       # MMU, TLB, paging, FIFO and LRU
├── process/      # PCB and process generation
├── reporting/    # Per-tick and final reports
├── resource/     # Resource allocation and deadlock handling
└── scheduler/    # Ready queues and CPU scheduling

Requirements

  • Java Development Kit (JDK)
  • A shell environment that supports find
  • Commands must be executed from the project root directory

Check the installed Java version:

java -version
javac -version

Compilation

Remove any previous build output, create the output directory, and compile all Java source files:

rm -rf out
mkdir out
javac -Xlint:all -d out $(find src -name "*.java")

Compiled .class files are written to the out directory.

Running the Simulator

The general command is:

java -cp out os.simulator.app.Main [fifo|lru]

Run with FIFO page replacement

java -cp out os.simulator.app.Main fifo

When fifo is selected, the simulator uses FIFO to choose a victim page whenever a page fault occurs while all physical-memory frames are occupied.

Run with LRU page replacement

java -cp out os.simulator.app.Main lru

When lru is selected, the simulator uses LRU to choose the least recently used victim page whenever a page fault occurs while all physical-memory frames are occupied.

Run with the default option

java -cp out os.simulator.app.Main

The simulator uses its configured default page-replacement policy when no policy argument is provided.

Output

The simulation report is printed to the console and written to:

output.txt

The file is overwritten on each run.

The report header shows the active page-replacement policy:

Concurrent OS Simulator
Page Replacement Policy: FIFO
Worker Threads: 4
Output File: output.txt

or:

Concurrent OS Simulator
Page Replacement Policy: LRU
Worker Threads: 4
Output File: output.txt

Each tick reports information such as:

  • Current system clock
  • Running process and CPU state
  • System, Interactive, and Background ready queues
  • TLB hit rate and entries
  • Physical-memory usage
  • Page faults and disk activity
  • Resource availability
  • Deadlock-monitor status
  • Context-switch count
  • Events generated during the tick

At the end of the simulation, a final summary reports statistics such as:

  • Final system clock
  • Total number of processes
  • Normal process completions
  • Deadlock victims
  • Recovered deadlocks
  • CPU idle ticks
  • Context switches
  • TLB hits and misses
  • TLB hit rate
  • Page faults
  • Average turnaround time

Page Replacement

The selected command-line argument controls the page-replacement policy used for physical memory.

For FIFO:

[PAGE-REPLACEMENT] FIFO selected frame ...

For LRU:

[PAGE-REPLACEMENT] LRU selected frame ...

A message such as the following refers to TLB replacement, not physical-memory page replacement:

[TLB] FIFO evicted ...

The TLB and physical memory use separate replacement mechanisms.

Dirty Pages

A successful WRITE access marks the corresponding page as dirty:

[MEMORY] WRITE by P5 on page 5; page marked DIRTY

If a dirty page is selected as a victim, it is written back before eviction:

[PAGE-OUT] Dirty page 5 of P5 written back before eviction
[PAGE-REPLACEMENT] FIFO selected frame ...

Scheduling Behavior

The simulator uses three ready queues:

  • System processes use FCFS.
  • Interactive processes use Round Robin.
  • Background processes use SRTF.

The queues use fixed priorities:

System > Interactive > Background

Aging promotes processes that wait too long and reduces the risk of starvation.

Resource Management and Deadlock Recovery

Processes may request and release instances of the configured resource types. A request is granted when enough resources are available; otherwise, the process enters the waiting state.

The deadlock monitor runs periodically. When a deadlock is detected, one process is selected as the victim. The victim is terminated, and its resources and memory frames are released so blocked processes can continue.

Complete Example

rm -rf out
mkdir out
javac -Xlint:all -d out $(find src -name "*.java")

java -cp out os.simulator.app.Main fifo

To run the simulator with LRU instead:

java -cp out os.simulator.app.Main lru

About

A concurrent Java-based operating system simulator featuring multilevel CPU scheduling, virtual memory and paging, TLB, page replacement, disk I/O, process synchronization, and deadlock detection.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages