A full-stack Operating Systems simulation project for detecting deadlocks using:
- Resource Allocation Graph (RAG) cycle detection
- Banker's Algorithm safety analysis
- Recovery and prevention recommendations
- Interactive frontend simulation and graph visualization
- Downloadable PDF reports
The backend is built with Flask and serves both API endpoints and the frontend UI.
- Detects deadlocks from user-defined processes and resources
- Uses two detection strategies:
- Graph cycle detection (NetworkX)
- Banker's Algorithm safety check
- Applies consistency rule to avoid contradictory outcomes across algorithms
- Generates Resource Allocation Graph image (
/api/graph) - Produces step-by-step simulation timeline (
/api/simulateand included in/api/detect) - Suggests deadlock recovery actions and prevention strategies
- Exports professional PDF report (
/api/report) - Includes unit tests for algorithms, detection flow, and strategy modules
- Python 3
- Flask + Flask-CORS
- NetworkX
- Matplotlib (headless/Agg)
- ReportLab (PDF generation)
- Gunicorn (production server)
- Vanilla HTML/CSS/JavaScript frontend
.
├── backend/
│ ├── app.py # Flask app entrypoint + static serving
│ ├── requirements.txt # Python dependencies
│ ├── algorithms/
│ │ ├── rag_builder.py # Builds Resource Allocation Graph
│ │ ├── cycle_detection.py # Deadlock cycle detection logic
│ │ ├── bankers_algorithm.py # Safety-state analysis
│ │ └── detection_engine.py # Orchestrates all detection pipelines
│ ├── api/
│ │ └── routes.py # REST endpoints
│ ├── models/
│ │ ├── process.py
│ │ ├── resource.py
│ │ └── system_state.py
│ ├── resolution/
│ │ ├── recovery.py # Recovery actions (terminate/preempt/suggest)
│ │ └── prevention.py # Prevention condition analysis
│ ├── utils/
│ │ ├── input_parser.py
│ │ ├── validator.py
│ │ ├── logger.py
│ │ └── report_generator.py
│ └── tests/
│ ├── test_detection.py
│ └── test_algorithms.py
├── frontend/
│ ├── index.html # UI shell
│ ├── app.js # Interaction logic and API integration
│ └── style.css # Dashboard styling
└── RENDER_DEPLOYMENT.md # Render deployment notes
- User defines resources (with instance counts) and processes (allocated/requested/max_need).
- Backend validates and parses input into system-state models.
- Detection engine runs:
- RAG build + cycle detection
- Banker's Algorithm safe/unsafe analysis
- Backend returns:
- final deadlock verdict
- involved processes
- algorithm-level details
- graph metrics and generated graph URL
- simulation steps
- recovery and prevention recommendations
Base path: /api
Runs full deadlock detection and returns all analysis data.
Request body:
{
"processes": [
{
"pid": "P1",
"allocated": ["R1"],
"requested": ["R2"],
"max_need": ["R1", "R2"]
}
],
"resources": [
{ "rid": "R1", "instances": 1 },
{ "rid": "R2", "instances": 1 }
]
}Response includes:
deadlockinvolved_processescycle_detectionbankers_algorithmgraph_inforesolutionpreventionsimulationgraph_url
Returns simulation steps only.
Generates and downloads a PDF report for the submitted system state.
Returns latest generated graph image (image/png).
Returns sample input payload for quick testing.
Health endpoint.
git clone <your-repo-url>
cd Automated-Deadlock-Detection-Tool-TejaWindows (PowerShell):
python -m venv .venv
.venv\Scripts\Activate.ps1macOS/Linux:
python3 -m venv .venv
source .venv/bin/activatepip install -r backend/requirements.txtcd backend
python app.pyApp URLs:
- Frontend:
http://localhost:5000 - API health check:
http://localhost:5000/api/health
From backend/:
python -m unittest discover testsUse the same settings documented in RENDER_DEPLOYMENT.md:
- Build Command:
pip install -r backend/requirements.txt- Start Command:
gunicorn backend.app:appNotes:
- Matplotlib is configured for headless environments (
Aggbackend). - No environment variables are required for basic deployment.
If you just want a live URL quickly, use Render or Railway with these settings.
- Push this repo to your fork branch
ansh. - In Render, click New + -> Web Service -> connect your GitHub repo.
- Render will auto-read
render.yamlfrom repo root. - Click Create Web Service.
If Render asks for manual commands, use:
pip install -r backend/requirements.txtgunicorn app:app --chdir backendHealth check path:
/api/health
- Create a new project from GitHub repo.
- Select branch
ansh. - Railway will detect Python.
- Set start command to:
gunicorn app:app --chdir backend- Deploy and open generated URL.
- Backend serves frontend files directly.
- Same domain hosts UI and API.
- You only run one process (
gunicorn) and everything is live.
- Multi-instance resources are represented via
instancesin the resource list. - Per-process resource quantities are represented by repeating resource IDs in arrays.
- Example:
"allocated": ["R1", "R1"]means 2 units ofR1are allocated.
- Example:
- Add process priorities and starvation-aware recovery policies
- Persist simulation runs and generated reports
- Add authentication and role-based access for shared environments
- Add CI pipeline for tests and linting