0% found this document useful (0 votes)
88 views6 pages

Banker's Algorithm in Operating System (OS) - Javatpoint

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views6 pages

Banker's Algorithm in Operating System (OS) - Javatpoint

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Go to step 2;

6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint


2. And when the number of requested resources of each type is less than the available resource for
each process, go to step (3). As the expression suggests:

If Request(i) <= Available


Else Process P[i] must wait for the resource since it is not available for use.

3. When the requested resource is allocated to the process by changing state:

Available = Available - Request


Allocation(i) = Allocation(i) + Request (i)
Needi = Needi - Requesti

When the resource allocation state is safe, its resources are allocated to the process P(i). And if the
new state is unsafe, the Process P (i) has to wait for each type of Request R(i) and restore the old
resource-allocation state.

Example: Consider a system that contains five processes P1, P2, P3, P4, P5 and the three resource
types A, B and C. Following are the resources types: A has 10, B has 5 and the resource type C has 7
instances.

Process Allocation Max Available


A B C A B C A B C

P1 0 1 0 7 5 3 3 3 2

P2 2 0 0 3 2 2

P3 3 0 2 9 0 2

https://www.javatpoint.com/bankers-algorithm-in-operating-system 6/13
Answer the following questions using the banker's algorithm:
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint

1. What is the reference of the need matrix?

2. Determine if the system is safe or not.

3. What will happen if the resource request (1, 0, 0) for process P1 can the system accept this
request immediately?

Ans. 2: Context of the need matrix is as follows:

Need [i] = Max [i] - Allocation [i]


Need for P1: (7, 5, 3) - (0, 1, 0) = 7, 4, 3
Need for P2: (3, 2, 2) - (2, 0, 0) = 1, 2, 2
Need for P3: (9, 0, 2) - (3, 0, 2) = 6, 0, 0
Need for P4: (2, 2, 2) - (2, 1, 1) = 0, 1, 1
Need for P5: (4, 3, 3) - (0, 0, 2) = 4, 3, 1

Process Need
A B C

P1 7 4 3

P2 1 2 2

P3 6 0 0

P4 0 1 1

P5 4 3 1

https://www.javatpoint.com/bankers-algorithm-in-operating-system 7/13
Available Resources of A, B and C are 3, 3, and 2.
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
Now we check if each type of resource request is available for each process.

Step 1: For Process P1:

Need <= Available

7, 4, 3 <= 3, 3, 2 condition is false.

So, we examine another process, P2.

Step 2: For Process P2:

Need <= Available

1, 2, 2 <= 3, 3, 2 condition true

New available = available + Allocation

https://www.javatpoint.com/bankers-algorithm-in-operating-system 8/13
Step 3: For Process P3:
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
P3 Need <= Available

6, 0, 0 < = 5, 3, 2 condition is false.

Similarly, we examine another process, P4.

Step 4: For Process P4:

P4 Need <= Available

0, 1, 1 <= 5, 3, 2 condition is true

New Available resource = Available + Allocation

5, 3, 2 + 2, 1, 1 => 7, 4, 3

Similarly, we examine another process P5.

Step 5: For Process P5:

P5 Need <= Available

4, 3, 1 <= 7, 4, 3 condition is true

New available resource = Available + Allocation

7, 4, 3 + 0, 0, 2 => 7, 4, 5

Now, we again examine each type of resource request for processes P1 and P3.

Step 6: For Process P1:

P1 Need <= Available

7, 4, 3 <= 7, 4, 5 condition is true

New Available Resource = Available + Allocation

7, 4, 5 + 0, 1, 0 => 7, 5, 5

So, we examine another process P2.

Step 7: For Process P3:

https://www.javatpoint.com/bankers-algorithm-in-operating-system 9/13
New Available Resource = Available + Allocation
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
7, 5, 5 + 3, 0, 2 => 10, 5, 7

Hence, we execute the banker's algorithm to find the safe state and the safe sequence like P2,
P4, P5, P1 and P3.

Ans. 3: For granting the Request (1, 0, 2), first we have to check that Request <= Available, that is (1,
0, 2) <= (3, 3, 2), since the condition is true. So the process P1 gets the request immediately.

← Prev Next →

For Videos Join Our Youtube Channel: Join Now

Feedback

Send your Feedback to [email protected]

Help Others, Please Share

https://www.javatpoint.com/bankers-algorithm-in-operating-system 10/13
tutorial
Splunk SPSS Transact-SQL
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
Swagger

Tumblr tutorial React tutorial Regex tutorial Reinforcement


learning tutorial
Tumblr ReactJS Regex
Reinforcement
Learning

R Programming RxJS tutorial React Native Python Design


tutorial tutorial Patterns
RxJS
R Programming React Native Python Design
Patterns

Python Pillow Python Turtle Keras tutorial


tutorial tutorial
Keras
Python Pillow Python Turtle

Preparation

Aptitude Logical Verbal Ability Interview


Reasoning Questions
Aptitude Verbal Ability
Reasoning Interview Questions

Company
Interview
Questions
Company Questions

Trending Technologies

https://www.javatpoint.com/bankers-algorithm-in-operating-system 11/13

You might also like