Lab 14 - Bankers Algorithm
Lab 14 - Bankers Algorithm
Let ‘n’ be the number of processes in the system and ‘m’ be the number of resources
types.
Available:
It is a 1-d array of size ‘m’ indicating the number of available resources of each
type.
Available [ j ] = k means there are ‘k’ instances of resource type Rj
Max:
It is a 2-d array of size ‘n x m’ that defines the maximum demand of each process
in a system.
Max[ i, j ] = k means process Pi may request at most ‘k’ instances of resource
type Rj.
Allocation:
It is a 2-d array of size ‘n x m’ that defines the number of resources of each type
currently allocated to each process.
Allocation[ i, j ] = k means process Pi is currently allocated ‘k’ instances of
resource type Rj
Need :
It is a 2-d array of size ‘n x m’ that indicates the remaining resource need of each
process.
Need [ i, j ] = k means process Pi currently need ‘k’ instances of resource type Rj
for its execution.
How to determine Need:
Need [ i, j ] = Max [ i, j ] – Allocation [ i, j ]
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.
Bankers Algorithm:
Banker’s algorithm consists 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:
Resource-Request Algorithm:
Let, Requesti be the request array for process Pi. Requesti [j] = k means process Pi
wants k instances of resource type Rj. When a request for resources is made by
process Pi, the following actions are taken:
Finally, run the safety algorithm to determine that with the new state of system weather
there is deadlock or not .
Question2. Is the system in a safe state? If Yes, then what is the safe sequence?
We must determine whether this new system state is safe. To do so, we again execute Safety
algorithm on the above data structures.
Hence the new system state is safe, so we can immediately grant the request for process P1 .
Lab Assignment:
Implement the Bankers algorithm and demonstrate its working with different data.