Skip to content

Holmes-99/-OS-Scheduler-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Typing SVG

Python Scheduling Deadlock CLI Status


๐Ÿ“‹ Abstract

A high-fidelity Operating System simulator that models:

  • CPU scheduling (Preemptive Priority + Round Robin)
  • Resource allocation & contention
  • Deadlock detection and recovery
  • Starvation prevention via aging

Built as an interactive CLI system, allowing users to step through execution tick by tick and observe real OS behavior in real time.


Interactive CLI Experience

[Time = 42]

 Running:   P2
 Ready:     P0, P3
 Waiting:   P1 (R2)
 IO Queue:  P4 (3 ticks)

Command โ†’ [Enter = step | a = auto-run]

Features

  • โฑ๏ธ Step-by-step execution (Enter)
  • โšก Auto-run mode (a)
  • ๐Ÿ“Š Live queue visualization
  • ๐ŸŽจ Pink-themed ANSI interface

โš™๏ธ Process Lifecycle

graph LR
    A[NEW] --> B[READY]
    B --> C[RUNNING]
    C -->|Preempt| B
    C -->|Request Resource| D[WAITING]
    C -->|IO Burst| E[IO]
    D --> B
    E --> B
    C --> F[TERMINATED]
Loading

๐Ÿ”ฎ Scheduling Engine

๐Ÿง  Hybrid Scheduling Strategy

Priority Scheduling (Preemptive)
        +
Round Robin (Same Priority)
        +
Aging Mechanism

Behavior

  • ๐ŸŽฏ Higher priority always wins
  • ๐Ÿ” Same priority โ†’ Round Robin (Quantum = 5)
  • โœจ Aging every 10 ticks โ†’ prevents starvation

๐Ÿšจ Deadlock Engine

Detection

  • Resource Allocation Graph (Banker-style reduction)
  • Runs every clock tick

Recovery Strategy

1. Detect circular wait
2. Select victim (lowest priority)
3. Terminate process
4. Release all resources
5. Resume system safely

๐Ÿ“ Instruction Model

Type Example Description
CPU 5 Execute for 5 time units
Request R[1,2] Request 2 units of Resource 1
Free F[1,2] Release resources
IO IO{3} Perform IO for 3 ticks

๐Ÿงช Simulation Scenarios

๐Ÿ”ด Deadlock Recovery

P0 holds R1 โ†’ needs R2
P1 holds R2 โ†’ needs R1

๐Ÿ’ฅ Deadlock detected!
๐Ÿ’€ Killing victim: P1
๐Ÿ”“ Resources released

๐ŸŸข Starvation Prevention (Aging)

Initial Priority: P0 = 20 (very low)

โœจ Aging Triggered
โ†’ P0 priority: 20 โ†’ 19 โ†’ 18 ...

โœ… Eventually scheduled

๐Ÿ–ฅ๏ธ Example Output

[T=15]

Running โ†’ P1
Ready   โ†’ P0, P2
Waiting โ†’ P3 (R1 unavailable)

โœจ Aging: P0 priority improved โ†’ 4

----------------------------------
[T=16]

๐Ÿšจ Deadlock Detected!
๐Ÿ’€ Terminating P3
๐Ÿ”“ Resources Released

๐Ÿ“ Project Structure

OS-Scheduler-Pink/
โ”œโ”€โ”€ prj.py              # Core simulation engine
โ”œโ”€โ”€ scenario1.txt       # Deadlock case
โ”œโ”€โ”€ scenario2.txt       # Aging case
โ”œโ”€โ”€ scenario3.txt       # Complex deadlock chain
โ”œโ”€โ”€ scenario4.txt       # Crciular wait
โ””โ”€โ”€ README.md

โ–ถ๏ธ How to Run

python prj.py scenario1.txt

Controls

Key Action
Enter Step forward
a Auto-run
Ctrl+C Stop execution

๐ŸŒŸ Why This Project Stands Out

  • Simulates real OS concepts, not simplified models
  • Combines 3 scheduling techniques in one system
  • Implements actual deadlock recovery logic
  • Fully interactive (rare for OS projects)
  • Designed with clear visualization in mind

๐ŸŽ“ Academic Info

Course ENCS3390 โ€” Operating Systems
University Birzeit University ๐Ÿ‡ต๐Ÿ‡ธ
Student Shatha Abualrob
Semester Fall 2025/2026

Releases

No releases published

Packages

 
 
 

Contributors

Languages