Questions tagged [bankers-algorithm]

It's a Resource allocation and deadlock avoidance algorithm. which states Maximum number of instances of each resource type the process can claim.

DEFINITION:

“The Banker’s algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes a “s-state” check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue” – source Wikipedia.

WHY THE NAME BANKER'S?

“Like other algorithms, the Banker’s algorithm has some limitations when implemented. Specifically, it needs to know how much of each resource a process could possibly request. In most systems, this information is unavailable, making it impossible to implement the Banker’s algorithm.“ – source Wikipedia

DESIGN

“The Banker’s algorithm is run by the operating system whenever a process requests resources. The algorithm avoids deadlock by denying or postponing the request if it determines that accepting the request could put the system in an unsafe state (one where deadlock could occur). When a new process enters a system, it must declare the maximum number of instances of each resource type that may not exceed the total number of resources in the system. Also, when a process gets all its requested resources it must return them in a finite amount of time” – source Wikipedia

LIMITATION

“Like other algorithms, the Banker’s algorithm has some limitations when implemented. Specifically, it needs to know how much of each resource a process could possibly request. In most systems, this information is unavailable, making it impossible to implement the Banker’s algorithm.“ – source Wikipedia

Following Links can be referenced:

Sample Output

Enter the number of resources:4

Enter the number of processes:5

Enter  Claim Vector:8 5 9 7

Enter Allocated Resource Table:
2 0 1 1
0 1 2 1
4 0 0 3
0 2 1 0
1 0 3 0

Enter Maximum Claim table:
3 2 1 4
0 2 5 2
5 1 0 5
1 5 3 0
3 0 3 3

The Claim Vector is:    8   5   9   7
The Allocated Resource Table:
2   0   1   1
0   1   2   1
4   0   0   3
0   2   1   0
1   0   3   0

The  Maximum Claim Table:
3   2   1   4
0   2   5   2
5   1   0   5
1   5   3   0
3   0   3   3

Allocated resources:    7   3   7   5
Available resources:    1   2   2   2

Process3 is executing

The process is in safe state
Available vector:   5   2   2   5
Process1 is executing

The process is in safe state
Available vector:   7   2   3   6
Process2 is executing

The process is in safe state
Available vector:   7   3   5   7
Process4 is executing

The process is in safe state
Available vector:   7   5   6   7
Process5 is executing

The process is in safe state
Available vector:   8   5   9   7
23 questions
3
votes
1 answer

Related to the bankers algorithm

While the bank allocates resources dynamically ensuring the system is safe all the time , what if one of the threads doesn't give up the resources it has been allocated (due to some infinite loop or something) resulting in the bank's inability to…
2
votes
1 answer

Banker's Algorithm Issue : Can a process request resources more than it's need?

In the problem mentioned in the image, on request of p3 (0,2,0) the need of p3 is becoming negative(means it has an extra resource). According to other general rules the request can be granted since safe sequence exists : P1 -> P3 -> P2. Can it is…
lifeisshubh
  • 440
  • 1
  • 3
  • 22
2
votes
1 answer

Deadlock on banker's algorithm

When preforming the banker's algorithm, what happens when there is a deadlock? Will it pick the first one?
user2980816
  • 61
  • 1
  • 1
  • 4
2
votes
1 answer

Bankers Algorithm with realtime process

How can we give a process in taskmanager (like notepad.exe) as an input as process for my Bankers Algorithm (Deadlock detection) ???
2
votes
2 answers

Dijkstra's Bankers Algorithm

Could somebody please provide a step-through approach to solving the following problem using the Banker's Algorithm? How do I determine whether a "safe-state" exists? What is meant when a process can "run to completion"? In this example, I have four…
Blair
  • 3,646
  • 4
  • 27
  • 39
1
vote
1 answer

Banker's algorithm - can I allocate resources to a process if Work is less than Need

I'm reading about Banker's algorithm from here, I know that one condition to check if we can allocate available resource to a process is that check whether Work > Need, my wonder is that can we do so if Work < Need but Work + Allocation > Need. For…
Yifei Xiao
  • 59
  • 4
1
vote
2 answers

Why isn't my global allocation structure updating values correctly?

I've been working on a bankers algorithm implementation in C and it seems to work fine except the allocation matrix isn't adding values correctly. In the request resources function, I use a mutex lock at the beginning and unlock right before…
Jerum
  • 71
  • 2
  • 8
1
vote
1 answer

Read from File, Load arrays

I'm trying to implement Banker's Algorithm in Java, but I'm having trouble loading my arrays. Here is the code I'm working with public static void main(String[] args) throws FileNotFoundException { String filename = null; int need[][]; …
jynx678
  • 229
  • 3
  • 13
1
vote
1 answer

Teradata - Removing Banker's Rounding with changing settings

I need to mimic a calculation in excel. We have to get the excact answer. The calculation is rounded at several points. Excel round X.5 up. It looks like Teradata is using banker's rounding (round X.5 to the even #). I cannot change the setting…
0
votes
1 answer

Misunderstanding bankers algorithm?

I am trying to understand how a banker's algorithm works. I have an example of how it works on my university slides, but I am not sure why one of processes (in my case P4) has been skipped. Should it not be checked like this at this point? Did I…
c398wwsfa
  • 21
  • 5
0
votes
2 answers

How do I determine whether a deadlock will occur in this system?

N processes share M resource units that can be reserved and release only one at a time. The maximum need of each process does not exceed M, and the sum of all maximum needs is less than M+N. Can a deadlock occur in the system ?
Courtney
  • 5
  • 3
0
votes
1 answer

Bankers Algorithm thread creation not running the passed method completely

My request_resources method isn't being ran when I call it from a thread creation in my main. It should be creating a thread, requesting resources, checking safe state and then exiting. I'm not sure why it stalls after 2 threads and gives no output…
Jerum
  • 71
  • 2
  • 8
0
votes
1 answer

Creating multiple pthreads in a for loop in C

I'm working on the bankers algorithm and am using a loop to create my threads. The issue is that the loop in only creating 4 threads when 5 of them should have been created. I've examined my loop and everything seems correct unless I'm missing…
Jerum
  • 71
  • 2
  • 8
0
votes
2 answers

Unsafe State and Safe State

I have learned a little about Unsafe State and Safe State. Safe State is when there is no chance of deadlock occuring, while unsafe state doesn't mean a deadlock has occurred yet, but means that a deadlock could happen. What I'm trying to figure out…
0
votes
0 answers

how to call files as resources in Dev c++ bloodshed

The project ask to call 3 separate files in this project for the bankers algorithm one is called a driver include "banker.c" include "process.c"
kaycee25
  • 1
  • 1
1
2