Repository navigation
bankier algorithm
The algorithm starts with the current available resources and the maximum demand of each process.
When a process requests resources, the system checks if the requested resources are available. If the requested resources are less than or equal to the available resources, the system temporarily grants the resources to the process for testing purposes.
The system performs a safety check to determine if allocating the requested resources would result in a safe state. It simulates the allocation by marking the requested resources as allocated for that process and reducing the available resources accordingly.
The algorithm checks if the system remains in a safe state after allocating the requested resources. It uses a loop to iteratively find a process that can be completed with the available resources. If such a process is found, its allocated resources are released and added back to the available resources. The loop continues until no more processes can be completed or all processes are completed.
If the system can reach a safe state after allocating the requested resources, the resources are actually granted to the process. If not, the requested resources are not granted, and the process is kept waiting.
When the process finishes using the allocated resources, it releases them. The released resources are added back to the available resources.
The process repeats as new resource requests and releases occur.