Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 2 KB

File metadata and controls

27 lines (20 loc) · 2 KB

ABOUT

This is a C++ demonstration of the banker's algorithm as used for deadlock avoidance. It takes a system state of a set of processes' allocated resources, their maximum resources, and the current resources available as input, and it prints whether the system is in a safe state and a safe sequence for process execution to avoid deadlock if so.

The default system state used is a safe state whose resulting safe sequence is P3 -> P1 -> P0 -> P2 -> P4.

A more detailed description of how the program works is given in Description.md.

HOW TO USE

In a Linux environment with g++ installed, in a terminal in a directory containing the banker.cpp and input.txt files, the program may be compiled by running the following command:

g++ -o banker banker.cpp

And then executed by running:

./banker

The input file input.txt is structured such that the data for the "Available" table, then the "Allocation" table, then the "Max" table is written, each separated by an empty line. Each column is separated by a space and correpsonds to resource type A, B, or C in order. Each row is separated by a new line and corresponds to the process, P0 through P4 in order. Note that the "Available" table is one row long because the processes are not relevant to it. The values in the tables may be edited to any integer. By default, the number of processes is 5, and the number of resource types is 3, but these can be adjusted by editing the values that NUM_PROCESSES and NUM_RESOURCES, respectively, are initialized to at the beginning of banker.cpp, and then recompiling the program.

RESULTS

For the default example given in input.txt, program usage and output should look like this:

Safe

In other safe states, the program should give similar output but possibly a different safe sequence.

If an unsafe state is instead given, program usage and output should instead look like this:

Unsafe