Bankers algorithm problems

Prob. Consider the following snapshot of a system-

Process
Allocation
Max
Available
A
B
C
D
A
B
C
D
A
B
C
D
P0
0
0
1
2
0
0
1
2
1
5
2
0
P1
1
0
0
0
1
7
5
0




P2
1
3
5
4
2
3
5
6




P3
0
6
3
2
0
6
5
2




P4
0
0
1
4
0
6
5
6





Answer the following questions using the Banker’s algorithm-

(i)                 What is the content of the matrix need?
(ii)               Is the system in a safe state?

(iii)             If a request from process P1 arrives for (0,4,2,0), can the request be granted immediately?

Ans.



Banker’s algorithm: Need Calculation


Steps to calculate need:

Step 1: in row of process P0, use formula
Need=Max – Allocation

Step 2: Follow step 1 above for all other processes i.e. P1, P2, P3, P4, P5.

Result given below.


Bankers algorithm: Need calculation

Steps to calculate Safe state:

Image 1


Step 1: Find the process which have Need lesser than Available. 

If need of process is lesser than available, add its allocation to the available and remove that process from the table.

Here as shown below,

Need [Process P0]  is less than Available
Than,
New Available = Available + Allocation [Process P0] (Available value is updated in Image 2)

So ,

Safe state = [P0].
Image 2


Step 2: In STEP 1, We find the process P0 which have Need lesser than Available. 
We removed Process P0 from table, and updated the Available. (See Image 2).

Now we repeat Step 1 as explain above.

Here as shown below,

Need [Process P2]  is less than Available
Than,
New Available = Available + Allocation [Process P2](Available value is updated in Image 3)
So ,

Safe state =  [P0, P2].
Image 3


Step 3: In STEP 2, we find the process P2 which have Need lesser than Available. 
We removed Process P2 from table, and updated the Available.(See Image 3).

Now we repeat Step 1 as explain above.

Here as shown below,

Need [Process P1]  is less than Available
Than,
New Available = Available + Allocation [Process P1](Available value is updated in Image 4)
So ,

Safe state = [P0, P2, P1].
Image 4


Step 4: In STEP 3, we find the process P1 which have Need lesser than Available. 
We removed Process P1 from table, and updated the Available.(See Image 4).

Now we repeat Step 1 as explain above.

Here as shown below,

Need [Process P3]  is less than Available
Than,
New Available = Available + Allocation [Process P3](Available value is updated in Image 5)
So ,

Safe state = [P0, P2, P1, P3].
Image 5


Step 5: In STEP 4, we find the process P3 which have Need lesser than Available. 
We removed Process P3 from table, and updated the Available.(See Image 5).

Now we repeat Step 1 as explain above.

Here as shown below,

Need [Process P4]  is less than Available


Python Programming ↓ 👆
Java Programming ↓ 👆
JAVA EasyExamNotes.com covered following topics in these notes.
JAVA Programs
Principles of Programming Languages ↓ 👆
Principles of Programming Languages
EasyExamNotes.com covered following topics in these notes.

Practicals:
Previous years solved papers:
A list of Video lectures References:
  1. Sebesta,”Concept of programming Language”, Pearson Edu 
  2. Louden, “Programming Languages: Principles & Practices” , Cengage Learning 
  3. Tucker, “Programming Languages: Principles and paradigms “, Tata McGraw –Hill. 
  4. E Horowitz, "Programming Languages", 2nd Edition, Addison Wesley

    Computer Organization and Architecture ↓ 👆

    Computer Organization and Architecture 

    EasyExamNotes.com covered following topics in these notes.

    1. Structure of desktop computers
    2. Logic gates
    3. Register organization
    4. Bus structure
    5. Addressing modes
    6. Register transfer language
    7. Direct mapping numericals
    8. Register in Assembly Language Programming
    9. Arrays in Assembly Language Programming

    References:

    1. William stalling ,“Computer Architecture and Organization” PHI
    2. Morris Mano , “Computer System Organization ”PHI

    Computer Network ↓ 👆
    Computer Network

    EasyExamNotes.com covered following topics in these notes.
    1. Data Link Layer
    2. Framing
    3. Byte count framing method
    4. Flag bytes with byte stuffing framing method
    5. Flag bits with bit stuffing framing method
    6. Physical layer coding violations framing method
    7. Error control in data link layer
    8. Stop and Wait scheme
    9. Sliding Window Protocol
    10. One bit sliding window protocol
    11. A protocol Using Go-Back-N
    12. Selective repeat protocol
    13. Application layer
    References:
    1. Andrew S. Tanenbaum, David J. Wetherall, “Computer Networks” Pearson Education.
    2. Douglas E Comer, “Internetworking with TCP/IP Principles, Protocols, And Architecture",Pearson Education
    3. KavehPahlavan, Prashant Krishnamurthy, “Networking Fundamentals”, Wiley Publication.
    4. Ying-Dar Lin, Ren-Hung Hwang, Fred Baker, “Computer Networks: An Open Source Approach”, McGraw Hill.