Implementation of banker’s algorithm

Implementation of banker’s algorithm

Here you will learn the program code of implementation of banker’s algorithm in operating system lab using c programming.

 

What is Banker’s Algorithm?

The Banker’s Algorithm is a deadlock avoidance algorithm used in operating systems to manage the allocation of multiple resources among multiple processes. It was developed by Edsger Dijkstra.

The Banker’s Algorithm manages resource allocation to processes in an OS. It tracks available resources, process maximum demands, current allocations, and remaining needs.

 

Example of Implementation of banker’s algorithm

Output

Enter number of process: 5

Enter number of resources: 3

Enter total numbers of each resources: 10 5 7

Enter Max resources for each process:
for process 1:7 5 3

for process 2:3 2 2

for process 3:9 0 2

for process 4:2 2 2

for process 5:4 3 3

 

Enter allocated resources for each process:
for process 1:0 1 0

for process 2:2 0 0

for process 3:3 0 2

for process 4:2 1 1

for process 5:0 0 2

available resources:
3 3 2
Allocated matrix Max need
0 1 0| 7 5 3| 7 4 3
2 0 0| 3 2 2| 1 2 2
3 0 2| 9 0 2| 6 0 0
2 1 1| 2 2 2| 0 1 1
0 0 2| 4 3 3| 4 3 1
Process 2 completed
Available matrix: 5 3 2
Allocated matrix Max need
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
2 1 1| 2 2 2| 0 1 1
0 0 2| 4 3 3| 4 3 1
Process 4 completed
Available matrix: 7 4 3
Allocated matrix Max need
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 1 completed
Available matrix: 7 5 3
Allocated matrix Max need
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 3 completed
Available matrix: 10 5 5
Allocated matrix Max need
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 5 completed
Available matrix: 10 5 7
The system is in a safe state!

 

 

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top