The Banker's Algorithm is a critical deadlock avoidance method in operating…

2024

The Banker's Algorithm is a critical deadlock avoidance method in operating systems, designed to facilitate resource allocation without causing deadlock. It operates by maintaining information about the maximum resources Each process may require, the current allocated resources and the available resources in the system. The algorithm checks each resource request to determine, if granting it would leave the system in a safe state, meaning that there is always a sequence in which all processes can complete their execution without getting stuck due to resource unavailability. Each process must specify its maximum demand for each resource type before it starts execution. When a process requests additional resources, the algorithm checks if granting the request will keep the system in a safe state. If so, the resources are allocated otherwise the process must wait until its request can be safely fulfilled.
What information is used to determine if a resource request can be granted ?

  1. A.

    Available resources and current allocation of each process

  2. B.

    CPU utilization of each process

  3. C.

    Number of processes waiting for resources

  4. D.

    Arrival time of each process.

Attempted by 213 students.

Show answer & explanation

Correct answer: A

Key information used to determine if a resource request can be granted:

  • Available resources: the vector of free instances for each resource type.

  • Current allocation for each process: how many instances of each resource each process currently holds.

  • Maximum demand for each process: the declared maximum number of instances each process may request.

  • Need matrix: computed as Maximum demand minus Current allocation; this is the remaining resource each process may still request.

How a request is evaluated:

  1. Pre-checks: verify the requested resources do not exceed the process's remaining need and do not exceed the currently available resources (Request ≤ Need and Request ≤ Available). If either fails, do not grant the request.

  2. Tentative allocation: temporarily allocate the requested resources (Available := Available − Request; Allocation := Allocation + Request; Need := Need − Request).

  3. Run the safety algorithm: initialize Work := Available and Finish[i] := false for all processes. Find a process whose Finish is false and whose Need ≤ Work; if found, set Work := Work + Allocation for that process and Finish := true. Repeat until no such process exists.

  4. Decision: if all Finish values become true, the system is in a safe state and the request can be granted permanently. If not, roll back the tentative allocation and make the process wait.

Why this ensures deadlock avoidance:

  • By only granting requests that leave the system in a safe state, the algorithm ensures there exists a sequence of process completions that allows every process to finish without deadlock.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor