This project is a C++ implementation of Banker’s Algorithm, a classic operating systems algorithm used for deadlock avoidance.
The program checks whether a system is in a safe state based on the available resources, maximum resource requirements, allocated resources, and calculated resource needs for each process.
- Originally completed: 2024
- Refactored and published on GitHub: 2026
- Context: Operating Systems coursework project
This repository has been cleaned and documented for portfolio purposes.
- Implements Banker’s Algorithm in C++
- Calculates the remaining resource need for each process
- Checks whether the system is in a safe or unsafe state
- Uses vectors to represent available resources, maximum demand, allocated resources, and need matrices
- Demonstrates basic operating system deadlock avoidance logic
- C++
- Operating Systems concepts
- Banker’s Algorithm
- Resource allocation matrices
- Makefile
.
├── Bankers.cpp
├── Bankers.h
├── main.cpp
├── Makefile
├── .gitignore
└── README.md
The program uses the following matrices/vectors:
- Available: currently available resources
- Max: maximum resources each process may need
- Allocated: resources already allocated to each process
- Need: remaining resources required by each process
The Need matrix is calculated as:
Need = Max - Allocated
The algorithm then checks whether there is a safe sequence of process execution. If each process can eventually complete and release its resources, the system is considered safe. Otherwise, the system is unsafe and the request should be denied.
Use the Makefile:
makeThis creates an executable called:
bankersmake runOr run the executable directly:
./bankersDepending on the resource configuration, the program prints either:
System is in the safe mode, grant the request.
or:
System is not in the safe mode, deny the request.
Calculates the remaining resources required by each process:
need[i][j] = maxR[i][j] - allocated[i][j];Checks whether the system is in a safe state by repeatedly looking for a process whose remaining needs can be satisfied by the currently available resources.
Through this coursework project, I practised:
- Implementing an operating systems algorithm in C++
- Working with vectors and matrices
- Understanding deadlock avoidance
- Modelling resource allocation between processes
- Structuring C++ code using header and implementation files
- Preparing a small systems programming project for GitHub
Possible improvements include:
- Allowing users to enter custom process/resource values
- Printing the safe sequence when the system is safe
- Adding request-handling functionality for new resource requests
- Adding input validation
- Adding unit tests
- Refactoring the project into
srcandincludefolders
Amir Lorvand