Example of banker's algorithm

1.)System consists of five process (p1, p2, p3, p4, p5) and three resources (r1, r2 ,r3). Resources type r1 has 10 instances,resources type r2 has 5 instances and r3 has 7 instances. The following snapshot of the system has been taken:




Content of the matrix need is calculated as need = max - allocation



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 resources.

2) If Need is greater than available, next process need is taken for comparison.

3) If the above example,need of process p1 is (7,4,3) and available        is (3,3,2).    
                 need >= available
 so system will move for next process.


4)Need for process p2 is (1,1,2) and available (3,3,2),so

       need<= available(work)
(1,2,2) <= (3,3,2) =true

then finish[i] =true

request of p2 is granted and process pr is release the resources to the system.

work  := work+Allocation
work := (3,3,2)+(2,0,0)
          =(5,3,2)
This procedure is continued for all procedure.


5)Need for process p2 is (6,0,0) and available (5,3,2),so

       need<= available(work)
(6,0,0)<= (5,3,2) =false


6)process p4 need (0,1,1) is compared with available(5,3,2)

       need<= available
(0,1,1) <= (5,3,2) =true

then finish[i] =true
Available = Available +Allocation
                 =(5,3,2)+(2,1,1)
                 =(7,4,3) 


7)process p5 need (4,3,1) is compared with available(7,4,3)

       need< available
(4,3,1) < (7,4,3) =true

then finish[i] =true
Available = Available +Allocation
                 =(7,4,3)+(0,2,2)
                 =(7,4,5) 


8) One cycle is completed.again system takes all remaining process in sequence.so,process p1 need (7,4,3) is compared with new available (7,4,5).

need < available =true
(7,4,3) < (7,4,5)

 available = available + allocation
                =(7,4,5)+(0,1,0)=(7,5,5)


9)process p3 need (6,0,0) is compared with available(7,5,5)
need < available =true
 (6,0,0) < (7,5,5)

 available = available + allocation
                =(7,5,5)+(3,0,2)=(10,5,7)



SAFE SEQUENCE IS <p2,p4,p5,p1,p3>

0 comments:

Copyright © 2013 free coding