In: Computer Science
write a C/C++ program that implements the banker's algorithm. Verify your implementation using the data from the textbook as well as the attached, but unverified (meaning that it is possible the system is already in an unsafe state), file. The file format is as follows:
Line 1 contains a number of resources (m).
Line 2 contains the quantity for each resource (I.e., the resource vector.
Line 3 contains the number of processes (n).
Lines 4 through 3+n contain the Claim matrix. Each line contains the maximum resource requirements for one process.
Lines 4+n and beyond contain the Allocation matrix. Each line contains the current number of resources allocated to the process.
The Claim and Allocation of matrices are in the same process order.
Prerequisite: Banker’s Algorithm
The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety by simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-state” check to test for possible activities, before deciding whether allocation should be allowed to continue.
Following Data structures are used to implement the Banker’s Algorithm:
Let ‘n’ be the number of processes in the
system and ‘m’ be the number of resources
types.
Available:
Max :
Allocation :
Need :
Allocationi specifies the resources currently allocated to process Pi and Needi specifies the additional resources that process Pi may still request to complete its task.
Banker’s algorithm consist of Safety algorithm and Resource request algorithm
Safety Algorithm
The algorithm for finding out whether or not a system is in a safe state can be described as follows:
|