0% found this document useful (0 votes)
37 views14 pages

Banker's Algorithm 64

The Banker's algorithm is used to determine if a system is in a safe state to avoid deadlocks. It simulates allocating maximum resources to processes and makes an "s-state" check. It maintains data structures like Available, Max, Allocated, and Need matrices. An example shows calculating the Need matrix and checking if requests result in a safe state. The algorithm iterates through processes, allocating resources if the request leaves the system in a safe state, and returns to the Available vector when finished.

Uploaded by

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

Banker's Algorithm 64

The Banker's algorithm is used to determine if a system is in a safe state to avoid deadlocks. It simulates allocating maximum resources to processes and makes an "s-state" check. It maintains data structures like Available, Max, Allocated, and Need matrices. An example shows calculating the Need matrix and checking if requests result in a safe state. The algorithm iterates through processes, allocating resources if the request leaves the system in a safe state, and returns to the Available vector when finished.

Uploaded by

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

BANKER’S ALGORITHM

SUBMITTED TO:

PROF.USMAN SAIF
PRESENTED BY:

MUHAMMAD UMAIR

REG NO.G1F16BSCS0100
INTRODUCTION

The banker’s algorithm is a resource allocation and deadlock avoidance


algorithm that tests for safety by simulating the allocation for predetermined
maximum possible amounts of all resources, then makes an “s-state” check to test
for possible activities, before deciding whether allocation should be allowed to
continue.

Bankers algorithm is used in banking systems to determine whether a loan can be


granted or not.
AVOIDING DEADLOCK: BANKERS ALGORITHM

The system is said to be in a safe state if there exists a sequence of other valid system states that leads
to the successful completion of all processes.

• Processes request only 1 resource at a time.

• Request is granted only it results in a safe state.

• If request results in an unsafe state, the request is denied and the process continues to hold resources
it has until such time as it's request can be met.

• All requests will be granted in a finite amount of time.


DATA STRUCTURES ARE USED TO IMPLEMENT THE BANKER’S
ALGORITHM:

• Let ‘n’ be the number of processes in the system and ‘m’ be the number of resources
types.

• Available(m)
• Max (n x m)
• Allocated (n x m)
• Need (n x m)
EXAMPLE

• Assume we have following resources:


• 6 speakers
• 3 scanners
• 5 printers
• 2 hard disks

• Total=(6,3,5,2)
• Allocated=(4,1,3,2)
Allocation Matrix
Processes Speakers Scanners Printers Hard Disks

P1 2 0 1 0

P2 0 1 1 1

P3 1 0 0 1

P4 1 0 1 0

Need Matrix
Processes Speakers Scanners Printers Hard Disks
P1 2 0 2 1

P2 0 1 1 1

P3 0 1 1 0

P4 3 0 2 0

Now the vector Available= (2,2,2,0)


Ava= 2220
MAX P3= - 0110
Processes Speakers Scanners Printers Hard Disks Bal= 2110
+1111
P1 4 0 3 1
Ava= 3221
P1= - 2021
P2 0 2 2 0 Bal= 1200
+4031
Ava= 5231
P3 1 1 1 1
P2 = - 0111
Bal= 5120
P4 4 0 3 0 +0222
Ava= 5342
P4 = - 3020
Bal = 2322
+ 4030
Total = 6352
Working of banker's algorithm
ITERATION 1:
1.Need(P3) = (0,1,1,0) < (2,2,2,0) =Ava
2.When P3 Complete then return currently allocated resources, add the
Available vector.

(2,2,2,0) Current value of available

(1,0,0,1) Allocation(P3)

(3,2,2,1) Updated Available value


ITERATION 2:
1.Need(P1) = (2,0,2,1) < (3,2,2,1) =Ava
2.When P1 Complete then return currently allocated resources, add the
Available vector.

(3,2,2,1) Current value of available

(2,0,1,0) Allocation(P1)

(5,2,3,1) Updated Available value


ITERATION 3:
1. Need(P2) = (0,1,1,1) < (5,2,3,1) =Ava
2. When P2 Complete then return currently allocated resources, add the
Available vector.

(5,2,3,1) Current value of available

(0,1,1,1) Allocation(P2)

(5,3,4,2) Updated Available value


ITERATION 4:
1.Need(P4) = (3,0,2,0) < (5,3,4,2) =Ava
2.When P4 Complete then return currently allocated resources, add the
Available vector.

(5,3,4,2) Current value of available

(1,0,1,0) Allocation(P4)

(6,3,5,2) Updated Available value


RESULT:
• Notice that update value of Available vector same as original total
vector.
Total=(6,3,5,2)<(6,3,5,2)=Available

• Safe sequence that assures this safe state is <P3,P1,P2,P4>.

You might also like