## Description

Lab exercise 7 Implementation of Banker’s algorithm (deadlock avoidance)

## Aim:

Develop a C program to implement the Banker’s algorithm for deadlock avoidance

Algorithm:

1. Read the following

a. Number of processes.

b. Number of resources and number of instances of each resource available.

c. Maximum requirement of each process,

d. Allocated instances of resources

2. Determine the need of each process

3. Repeat the following till all processes are done.

a. Check if request of process i less than or equal to need of that process

i. If yes proceed

ii. Otherwise raise an error condition

b. Check if request of process i less than or equal to available instances

i. If yes proceed

ii. Otherwise wait till available.

c. Update the available vector, allocation vector and need vector

d. Generate safety sequence by running safety algorithm.

Sample Input/Output:

Banker’s Algorithm

1. Read Data

2. Print Data

3. Safety Sequence

4. Exit

Enter the option :1

Number of processes: 5 P0, P1, P2, P3, P4

Number of resources: 3 A B C

Number of Available instances of A: 3

Number of Available instances of B: 3

Number of Available instances of C: 2

Maximum requirement for P0: 7 5 3

Maximum requirement for P1: 3 2 2

Maximum requirement for P2: 9 0 2

Maximum requirement for P3: 2 2 2

Maximum requirement for P4: 4 3 3

Allocated instances to P0: 0 1 0

Allocated instances to P1: 2 0 0

Allocated instances to P2: 3 0 2

Allocated instances to P3: 2 1 1

Allocated instances to P4: 0 0 2

Enter the option: 2

Pid Alloc Max Need Avail

A B C A B C A B C A B C

P0 0 1 0 7 5 3 * * * 3 3 2

P1 2 0 0 3 2 2 * * *

P2 3 0 2 9 0 2 * * *

P3 2 1 1 2 2 2 * * *

P4 0 0 2 4 3 3 * * *

Enter the option: 3

Display the Safety Sequence:

* * * * *

Enter the option:4