In: Other
Deadlock –Banker’s Algorithm
A system has three resource types (A, B, C) and four processes {P1, P2, P3, P4 }. The total units of system resources are: (8, 5, 4) units of A, B and C, respectively. The maximum demands for each process is P1(1,2,3), P2(3,2,1), P3(6,5,4) and P4(4,4,2). The current allocation is: P1(0,1,1), P2(2,2,0) and P3(3,0,1) and P4(1,0,1).
(a) Allocation table is given for the 3 processes with the following four columns: PROCESS, ALLOCATION, MAX and NEED. And fill this table with the current allocation state.
(b) Is this state a safe state? Explain your answer by identifying a successful future sequence of processes that makes the state safe, or by explaining which processes are part of the problem that makes the state unsafe?
PROCESS ALLOCATION MAX NEED
A B C A B C A B C
* P0 4 5 0 1 3 6 3 2 6 (*P0 is just an example)
P1 0 1 1 1 2 3
P2 2 2 0 3 2 1
P3 3 0 1 6 5 4
P4 1 0 1 4 4 2
BANKER'S Algorithm
(a)
The banker's algorithm is designed to check the feasibility of task
with a given memory and a variety of process.It is designed so that
deadlock can be avoided in system
NEED=MAX-ALLOCATION
It is easy to remember the mathematical formula but the basic logic
is that to known that our program will work in worst scenario and
for that reason we assume this much resources we have given and in
the worst case it will take max resources so the in that moment
amount of resource required is taken as NEED here.
PROCESS ALLOCATION MAX NEED
A B C A B C A B C
P1 0 1 1 1 2 3 1 1 2
P2 2 2 0 3 2 1 1 0 1
P3 3 0 1 6 5 4 3 5 3
P4 1 0 1 4 4 2 3 4 1
(b)
Condition for safe state: -If all processes pass through work then
it is in the safe state.
allocation[A,B,C]=[6,3,3]//it is nothing but sum of all
allocation in their
// respected resource type
resource[A,B,C]=[8,5,4] //it is total sum of all resources
available[A,B,C]=resource[A,B,C]-allocation[A,B,C]//it is it's
formula
=[2,2,1]
work=available=[2,2,1] // Initially we take work=available;
But as we move forward if a process is executed then we update work
and that is the sum of initial work with allocation of that
process.It is done so because as soon as the process is executed we
can use the allocated resources of that process, for other
processes to execute
Any process will take place only if work[A,B,C]>=NEED[A,B,C] for that process.
Now we will check for all process that whether they can happen or not
Now for P1
since the need of C in P1 is high then work so P1 will not
execute
Now P2
Since need[A,B,C]<=work[A,B,C]
so P2 will get executed and now work will get updated
now work=work+allocation[P2]
work=[4,4,1]
Now P3
Since need[B,C]>work[B,C]
process will not take place
Now P4
Since need[A,B,C]<=work[A,B,C]
So P4 will take place
work+=allocation
work=[5,4,2]
Now P1 again
Since need[A,B,C]<=work[A,B,C]
So P1 will take place
work+=allocation
work=[5,5,3]
Now P3
Since need[A,B,C]<=work[A,B,C]
So P3 will take place
work+=allocation
work=[8,5,4]
since all the process are able to take place,this state is the
safe state
and the safe sequence is