Presentation is loading. Please wait.

Presentation is loading. Please wait.

Banker`s Algorithm Developed by Dijkstra in 1965

Similar presentations


Presentation on theme: "Banker`s Algorithm Developed by Dijkstra in 1965"— Presentation transcript:

1 Banker`s Algorithm Developed by Dijkstra in 1965
A deadlock avoidance algorithm Each process provides information about the resources it will need in order to complete execution

2 Deadlock Avoidance Requires that the system has some additional a priori information available. Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition A resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes

3 Banker’s Algorithm Used when there exists multiple instances of a resource type Each process must a priori claim maximum use When a process requests a resource, it may have to wait When a process gets all its resources, it must return them in a finite amount of time Always keep so many resources that satisfy the needs of at least one client

4 Banker’s Algorithm Based on a bank with a fixed amount of capital that operates on the following principles: No customer will be granted a loan exceeding bank’s total capital. All customers will be given a maximum credit limit when opening an account. No customer will be allowed to borrow over the limit. The sum of all loans won’t exceed the bank’s total capital. OS (bank) must be sure never to satisfy a request that moves it from a safe state to an unsafe one. Job with smallest number of remaining resources < = number of available resources

5 Banker`s Algorithm (Contd….)
Processes are like customers wanting to borrow money (resources) from a bank... A banker should not allocate cash when it cannot satisfy the needs of all its customers

6 Safe and Unsafe states The state of the system is the current allocation of resources to processes. A safe state is one in which there is at least one order in which all processes can be run to completion within a finite time without resulting in a deadlock. (It is possible to go from a safe state to an unsafe state.) The OS is analogous to a banker, and job requests are analogous to the clients. The system grants requests that result in safe states only. Unsafe states need not be deadlocked ; there is only a potential for deadlock. The banker’s algorithm assures that there is never such a possibility.

7 Banker’s Algorithm Assume that:
a resource can have multiple instances the OS has N processes, M resource types Initially, each process must declare the maximum no. of resources it will need. Calculate a safe sequence if possible.

8 Safe and Unsafe state A safe state cannot lead to deadlock.
An unsafe state may lead to deadlock. Deadlock is avoided by always keeping the system in a safe state (though this may reduce resource utilization) Deadlock Unsafe Safe

9 Example 1 Max no. of resources: 12 tape drives
Max needs Current Allocation P P P Currently, there are 3 free tape drives The OS is in a safe state, since <P1, P0, P2> is a safe sequence.

10 Example 2 Same as last slide, but P2 now has 3 tape drives allocated currently. Max needs Current Allocation P P P The OS is in an unsafe state.

11 Example 3 Suppose we have two resources, A, and B.
A has 6 instances and B has 3 instances. Can the system execute the following processes without deadlock occurring?

12 Solution Available: A= 1; B= 0
We can execute the processes in the sequence <P4, P1, P3, P2, P5> without deadlock.

13 Example 4 Consider six processes P0, P1…P5 and three resources A, B and C. Is executing the following processes a safe state.

14 Solution First find the resources that each process needs
The process is in safe state it is executed in the order (P1, P3, P4, P0, P2, P5)

15 Example 5 Suppose we have five processes and three resources A, B and C. A has 2 instances, B has 5 instances and C has 4 instances. Given the information below, can the system execute the following processes without deadlock occurring,.

16 Solution The Available is A=0, B=1 and C=0 The current need is

17 Example 6

18 Solution

19 Question

20 Problems with Banker’s Algorithm
. Users must state their maximum resource usage in advance, but many jobs are interactive and dynamic and users cannot anticipate their eventual requirements. Processes rarely know in advance how many resources they will need The number of processes changes as time progresses Resources once available can disappear The algorithm assumes processes will return their resources within a reasonable time Processes may only get their resources after an arbitrarily long delay


Download ppt "Banker`s Algorithm Developed by Dijkstra in 1965"

Similar presentations


Ads by Google