Sie sind auf Seite 1von 6

2/24/14 13(a) Explain the Bankers algorithm for deadlock avoidance with an illustration. | bituh.

com
www.bituh.com/2012/08/22/13a-explain-the-bankers-algorithm-for-deadlock-avoidance-with-an-illustration/ 1/6
bituh.com
be ready for your exam in last minute..
Search

About
13(a) Explain the Bankers algorithm for
deadlock avoidance with an illustration.
0
The Bankers algorithm is the best known of the avoidance strategies. The strategy is modelled after the
leading policies employed in banking system. The resource-allocation graph algorithm is suitable to a resource
allocation system with single instances of each resource type. It is not suitable for multiple instance of each
resource type. Bankers algorithm is suitable to a resource allocation system with multiple instances of each
resource type. The bankers algorithm makes decisions on granting a resource based on whether or not granting
the request will put the system into an unsafe state. Several data structures must be maintained to implement the
bankers algorithm. Let n be the number processes in the system and m be the number of resource types. We
need the following data structures:
(1) Available (2) Max (3) Allocation (4) Need I) Available: A vector of length m indicates the number of
available resources of each type. If available [j] = k, there are k instances of resource type R available.
2) Max: An n x m matrix defines the maximum demand of each process. If Max [i, j] = k, then process P. may
request at most k instances of resource type R
r
3) Allocation: An n x m matrix defines the number of resources of each type currently allocated to each
process. If allocation [i, j] = k, then P. is currently allocated k instances of resource type R
4) Need: An n x m matrix indicates the remaining resource need of each process. If Need |i, j] = k, then process
P. may need k more instances of resource type R, to complete its task. Need [i, j] Allocation [i, j].
Safety algorithm: Safety algorithm is used to find the state of the system: That is, system may be safe state or
unsafe state. Method for this is as follows:
1) Let work and finish be vector of length m and n respectively. Initialize work = Available and Finish [i] =
False for i = 1, 2, 3, 4, n.
2) Find an i such that both
a) Finish [i] = False b) Need fj] < work
If no such i exist, go to step 4.
2/24/14 13(a) Explain the Bankers algorithm for deadlock avoidance with an illustration. | bituh.com
www.bituh.com/2012/08/22/13a-explain-the-bankers-algorithm-for-deadlock-avoidance-with-an-illustration/ 2/6
3) Work : = Work + Allocation i
Finish [i] = true to step 2
4) If Finish [i] = true for all i, then the system is in a safe state. Resource-request algorithm: Let request, be the
request vector for process P. If Request, fj] = k, then process P. wants k instances of resource type R.. When a
request for resources is made by process P, the following actions are taken.
1) If Request. < Need
(
, then go to step 2. Otherwise, raise an eitor condition since the process has exceeded
its maximum claim.
2) If Request < Available, then go to step 3. Otherwise, P. must wait since the resources are not available.
3) Available : = Available Request.; Allocation : = Allocation + Request.; Need
;
: = Need
t
Request.;
If the resulting resource allocation stale is safe, the transaction is completed and process P. is allocated its
resources. If the new state is unsafe, then P. must wait to the Request, and the old resource allocation state is
restored.
Examples on Bankers algorithm:
1) System consists of five processes (P,, P
2
, P
3
, P
4
, P
s
) and three resources (R,, R R
3
). Resource type R, has
10 instances, resource type R, has 5 instances and R
}
has 7 instances. The following snapshot of the system has
been taken

ProcessAllocation Max

R,
r
2

R
i
P,0 l 0 i 5
P
2
2 0 0 3 2
P
3
P
4
3 0 2 9 0
2 I 1 2 2
Ps0 0 2 4 3
3
2
2/24/14 13(a) Explain the Bankers algorithm for deadlock avoidance with an illustration. | bituh.com
www.bituh.com/2012/08/22/13a-explain-the-bankers-algorithm-for-deadlock-avoidance-with-an-illustration/ 3/6
location.
Available
R, R.
R,
R,
2
2
2
3

Content of the matrix need is calculated as Need = Max A1
Process Need

R,
R
2
x,
P, 7 4 3
P
2
1 2 2
P
3
6 0 0
P, 0 1 1
P
5
4 3 1

Currently the system is in safe state.
Safe sequence: Safe sequence is calculated as follows:
1) Need of each process is compared with available. If need. < available;, then the resources are allocated to
that process and process will release the resource.
2) If need is greater than available, next process need is taken for comparison.
3) In the above example, need of process P. is (7, 4, 3) and available is (3, 3, 2).
need > available > False So system will move for next process.
4) Need for process P2 is (1, 2, 2) and available (3, 3, 2), so
need < available (work) (1, 2, 2) < (3, 3, 2) = True then Finish [i] = True
2/24/14 13(a) Explain the Bankers algorithm for deadlock avoidance with an illustration. | bituh.com
www.bituh.com/2012/08/22/13a-explain-the-bankers-algorithm-for-deadlock-avoidance-with-an-illustration/ 4/6
Request of P, is granted and processes P
2
is release the resource to the system.
Work : = Work + Allocation Work : = (3, 3, 2) + (2, 0, 0) : = (5, 3, 2)
This procedure is continued for all processes.
5) Next process P
3
need (6, 0,0) is compared with new available (5, 3,2).
Need > Available = False (6 0 0) > (5 3 2)
6) Process P
4
need (0, 1, 1) is compared with available (5, 3, 2).
Need < available
(0 1 1) < (5 3 2) = True
Available = Available + Allocation
= (5 3 2) + (2 1 1) = (7 4 3) (New available)
7) Then process P
5
need (4 3 1) is compared with available (7 4 3)
Need < Available
(4 3 1) < (7 4 3) = True
Available = Available + Allocation
= (7 4 3) + (0 0 2) = (7 4 5) (New available)
8) Process P, need (7 4 3) and available (7 4 5). If this request is granted then the system may be in the
deadlock state. After granting the request, available resource is (0 0 2) so the system is in unsafe state.
9) Process P
3
need is (6 0 0) and available (7 4 5)
.. Need < Available (6 0 0) < (7 4 5) = True Available = Available + Allocation
= (7 4 5) + (3 0 2) = (10 4 7) = (New available)
10) Last the remaining process PI need (7 4 3) and available is (10 4 7)
Need < Available (7 4 3) < (10 4 7) = True

Available = Available + Allocation = (10 4 7) + (0 I 0) = (10 5 7) Safe sequence is < P
1
P
4
P
5
P
0
P,> Weakness
of Bankers algorithm:
1. It requires that there be a fixed number of resources to allocate.
2/24/14 13(a) Explain the Bankers algorithm for deadlock avoidance with an illustration. | bituh.com
www.bituh.com/2012/08/22/13a-explain-the-bankers-algorithm-for-deadlock-avoidance-with-an-illustration/ 5/6
2. The algorithm requires that users sLate their maximum needs (request) in advance.
3. Number of users must remain fixed.
4. The algorithm requires that the bankers grant all requests within a finite time.
5. Algorithm requires that process returns ail resource within a finite time.
Categories: BTECH [IT], NOV-DEC-2006, Operating Systems
This post was written by shalini, posted on August 22, 2012 Wednesday at 7:46 am
Leave a Reply
Your email address will not be published.
Name
Email
Website
Comment
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym
title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q
cite=""> <strike> <strong>
Post Comment
Search
Categories
open all | close all
BE [Civil] (313)
BE [CS] (1500)
BE [ECE] (522)
BE [EEE] (15)
BTECH [IT] (1088)
Others (58)
2/24/14 13(a) Explain the Bankers algorithm for deadlock avoidance with an illustration. | bituh.com
www.bituh.com/2012/08/22/13a-explain-the-bankers-algorithm-for-deadlock-avoidance-with-an-illustration/ 6/6
Disclaimer:All data and information provided on this site is for informational purposes only.
http://bituh.com makes no representations as to accuracy, completeness, currentness, suitability,
or validity of any information on this site and will not be liable for any errors, omissions, or
delays in this information or any losses, injuries, or damages arising from its display or use.
Copyright bituh.com. All rights reserved.

Das könnte Ihnen auch gefallen