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.
- 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
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
- 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 -versionRemove 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.
The general command is:
java -cp out os.simulator.app.Main [fifo|lru]java -cp out os.simulator.app.Main fifoWhen fifo is selected, the simulator uses FIFO to choose a victim page whenever a page fault occurs while all physical-memory frames are occupied.
java -cp out os.simulator.app.Main lruWhen 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.
java -cp out os.simulator.app.MainThe simulator uses its configured default page-replacement policy when no policy argument is provided.
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
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.
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 ...
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.
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.
rm -rf out
mkdir out
javac -Xlint:all -d out $(find src -name "*.java")
java -cp out os.simulator.app.Main fifoTo run the simulator with LRU instead:
java -cp out os.simulator.app.Main lru