ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU class(2019-2020-1) > student directories > 2017329621139_徐政辉 >
homework5 Version 0
👤 Author: by calmwalteroutlookcom 2019-10-19 17:21:48
describe your understadings about Banker's Algorithm, and give your own demo example.

bankers algorithm is used for deadlock avoidance.
first we define something to use for the bankers algorithm.
1.Available:this means the resources that is available.
2.Max:this means the maximum demand of resources of each process.
3.Allocation:number of resources that is allocated by the process.
4.Need:the remaining resource need of each process.

the algorithm:

1.find whether the system is in a safe state.
1)Let Work and Finish be vectors of length m and n, respectively.Initialize Work = Available and Finish[i] = false for i=0,1,...,n-1
2)find an i such that both:
a. finish[i]==false
b. need[i]<=Work
if no such i exists,go to step 4.
3)Work = Work + Allocation[i]
Finish[i]=true
Go to step 2
4)If Finish==True for all i, then the system is in a safe state.

2.determines if requests can be safely granted.
1).if Requests[i]<=Need[i], go to step 2. Otherwise, raise an error condition, since the process has exceeded its maximum claim.
2).if Requsets[i]<=Available, go to step3.Otherwise ,P[i] must wait, since the resources are not available.
3).Have the system pretend to have allocated the requested resources to process P[i] by modifying the state as follows:
Available = Available -Request[i];
Allocation[i] = Allocation[i] + Request[i];
Need[i] = Needp[i] - Requests[i];

my bankers algorithm example:
set that we have three processes and two resources and we have 6 resources instance for A and 4 resources instance for B.

Allocation MAX Available Need
-------------------------------------------------------------
A B A B A B A B

p0 0 1 3 2 2 1 3 1

p1 2 1 3 4 1 3

p2 4 1 5 2 1 1
--------------------------------------------------------------

so we first judge if the system in a safe state:

1.p2 is first finished and then the state became:

Allocation MAX Available Need
-------------------------------------------------------------
A B A B A B A B

p0 0 1 3 2 6 2 3 1

p1 2 1 3 4 1 3

p2 0 0 0 0 0 0
--------------------------------------------------------------


2.p0 is second finished and then the state became:

Allocation MAX Available Need
-------------------------------------------------------------
A B A B A B A B

p0 0 0 0 0 6 3 0 0

p1 2 1 3 4 1 3

p2 0 0 0 0 0 0
--------------------------------------------------------------

3.p1 is finished.

so we get the sequence: p2->p0->p1, and it's in a safe state.

Please login to reply. Login

Reversion History

Loading...
No reversions found.