Skip to content

KrishnaPassi1818/bankers-algorithm-visual-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Banker's Algorithm Simulation with Visualization

A Python-based simulation of the Banker's Algorithm used in Operating Systems for deadlock avoidance.
This project implements the algorithm step-by-step and generates multiple visualizations to demonstrate how resources are allocated and released during safe execution.

The program calculates the Need Matrix, checks whether the system is in a Safe State, determines the Safe Sequence, and generates graphical outputs using Matplotlib.


Project Objective

The goal of this project is to simulate how an operating system avoids deadlocks using the Banker's Algorithm.
The program evaluates whether processes can safely execute based on available resources and maximum resource requirements.

The simulation also provides visual insights into resource allocation and system safety using graphs.


Technologies Used

  • Python 3
  • NumPy
  • Matplotlib
  • VS Code

Project Structure

bankers-algorithm-simulation/ │ ├── main.py # Runs the program ├── bankers_algorithm.py # Core Banker’s Algorithm logic ├── visualization.py # Graph generation functions ├── graphs/ # Generated output graphs │ ├── README.md └── requirements.txt (optional)


Algorithm Explanation

Banker's Algorithm determines whether the system is in a safe state by checking if there exists a sequence of processes such that each process can finish execution without causing a deadlock.

The algorithm uses the following matrices:

Allocation Matrix

Resources currently allocated to each process.

Maximum Matrix

Maximum resources each process may require.

Need Matrix

Need = Maximum - Allocation

Available Resources

Resources currently available in the system.

The algorithm simulates process execution and checks if a safe sequence exists.


Program Output

The program prints:

  • Maximum Resource Matrix
  • Allocation Matrix
  • Need Matrix
  • Available Resources
  • Safe Sequence
  • Safe / Unsafe system state

Example output: System is in SAFE state Safe sequence: P1 P3 P4 P0 P2

Graphs generated successfully in 'graphs' folder.


Generated Visualizations

The program automatically generates the following graphs inside the graphs/ folder.

Resource Allocation Graph

Shows how resources are distributed among processes.

Need Matrix Heatmap

Visual representation of resources still required by processes.

Maximum Resource Matrix Heatmap

Displays maximum possible resource demand.

Safe Sequence Graph

Shows the order in which processes safely execute.

Resource Progress Graph

Demonstrates how available resources change after each process execution.


How to Run the Project

1 Install dependencies

pip install numpy matplotlib

2 Run the program

python main.py

3 Output

Graphs will be generated automatically in the graphs/ folder.


Sample Input Used

Processes: 5
Resources: 3

Allocation Matrix: P0: 0 1 0 P1: 2 0 0 P2: 3 0 2 P3: 2 1 1 P4: 0 0 2

Maximum Matrix: P0: 7 5 3 P1: 3 2 2 P2: 9 0 2 P3: 2 2 2 P4: 4 3 3

Available Resources: [3,3,2]


Key Features

  • Implementation of Banker's Deadlock Avoidance Algorithm
  • Safe state detection
  • Safe sequence generation
  • Matrix calculations using NumPy
  • Multiple Matplotlib visualizations
  • Automatic graph export

Educational Purpose

This project is designed for Operating System coursework and practical demonstrations.
It helps visualize how operating systems manage resources safely and prevent deadlocks.


Author

Krishna
B.Tech Computer Science Engineering
Operating Systems Project

About

A Python simulation of the Banker's Algorithm for deadlock avoidance in Operating Systems with visualizations for resource allocation, safe sequence, and resource progression using Matplotlib.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages