Search Header Logo
Deadlock_BankersAlgo

Deadlock_BankersAlgo

Assessment

Presentation

Computers

University

Practice Problem

Hard

Created by

Pushpendra Pateriya

Used 3+ times

FREE Resource

6 Slides • 4 Questions

1

media

Banker's Algorithm

2

Banker's Algorithm

  • The Banker's algorithm is a resource allocation and deadlock avoidance algorithm used in operating systems.

  • It was developed by Edsger Dijkstra in 1965.

  • The algorithm helps prevent deadlock in a system by allowing processes to request resources while ensuring that resources are allocated in a safe and non-blocking manner.

  • It is commonly used in multi-process, multi-resource systems, such as computer systems and operating systems.

3

Banker's Algorithm

The following data structures, where n is the number of processes in the system and m is the number of resource types:

  • Available. A vector of length m indicates the number of available resources of each type. If Available[j] equals k, then k instances of resource type Rj are available.

  • Max. An n × m matrix defines the maximum demand of each process.

    If Max[i][j] equals k, then process Pi may request at most k instances of resource type Rj .

  • Allocation. An n × m matrix defines the number of resources of each type currently allocated to each process. If Allocation[i][j] equals k, then process Pi is currently allocated k instances of resource type Rj .

  • Need. An n × m matrix indicates the remaining resource need of each process. If Need[i][j] equals k, then process Pi may need k more instances of resource type Rj to complete its task.

    Need[i][j] = Max[i][j] − Allocation[i][j].

4

Safety Algorithm

1. Let Work and Finish be vectors of length m and n, respectively. Initialize

Work = Available and Finish[i] = false for i = 0, 1, ..., n − 1.

2. Find an index i such that both

a. Finish[i] == false

b. Needi ≤ Work

If no such i exists, go to step 4.

3. Work = Work + Allocationi

Finish[i] = true

Go to step 2.

4. If Finish[i] == true for all i, then the system is in a safe state.


Note: This algorithm may require an order of m × n2 operations to determine whether

a state is safe.

5

Resource-Request Algorithm

Let Requesti be the request vector for process Pi .
If Requesti [j] == k, then process Pi wants k instances of resource type Rj . When a request for resources is made by process Pi, the following actions are taken:

  1. If Requesti ≤ Needi , go to step 2. Otherwise, raise an error condition, since the process has exceeded its maximum claim.

  2. If Requesti ≤ Available, go to step 3. Otherwise, Pi must wait, since the resources are not available.

  3. Have the system pretend to have allocated the requested resources to process Pi by modifying the state as follows:

    1. Available = Available–Requesti ;

    2. Allocationi = Allocationi + Requesti ;

    3. Needi = Needi –Requesti ;

If the resulting resource-allocation state is safe, the transaction is completed, and process Pi is allocated its resources. However, if the new state is unsafe, then Pi must wait for Requesti , and the old resource-allocation state is restored.

6

Example

Consider a system with five processes P0 through P4 and three resource types A, B, and C. Resource type A has ten instances, resource type B has five instances, and resource type C has seven instances. Suppose that, at time T0, the following snapshot of the system has been taken:









The system is currently in a safe state or not?

media

7

Multiple Choice

In the Banker's algorithm, which data structures are used to keep track of available, maximum, and allocated resources?

1

Stacks

2

Linked lists

3

Queues

4

Arrays

8

Multiple Choice

What is the purpose of the safety check in the Banker's algorithm?

1

To allocate resources to a process

2

To check if a process has enough resources

3

To ensure that resource allocation won't lead to deadlock

4

To terminate processes

9

Multiple Choice

When a process makes a resource request in the Banker's algorithm, what must be checked before granting the request?

1

If the process has enough money

2

If the process has the highest priority

3

If the process is the only one running

4

If the requested resources are available and the state remains safe

10

Multiple Choice

What happens if a resource request in the Banker's algorithm cannot be satisfied without violating safety?

1

The process is terminated

2

The request is granted anyway

3

The process is paused until the resources become available

4

The request is denied

media

Banker's Algorithm

Show answer

Auto Play

Slide 1 / 10

SLIDE