7
Most read
10
Most read
15
Most read
Operating Systems
Unit 3
CPU Scheduling:
1. Scheduling Concepts,
2. Performance Criteria,
3. Process States,
4. Process Transition Diagram,
5. Schedulers,
6. Process Control Block (PCB),
7. Process address space,
8. Process identification information,
9. Threads and their management,
10. Scheduling Algorithms,
11. Multiprocessor Scheduling.
Deadlock:
1. System model,
2. Deadlock characterization,
3. Prevention,
4. Avoidance and detection,
5. Recovery from deadlock.
Deadlock : System model
• Deadlock is a situation where a set of processes are
blocked because each process is holding a resource and
waiting for another resource acquired by some other
process.
• Consider an example when two trains are coming toward
each other on the same track and there is only one track,
none of the trains can move once they are in front of
each other.
• Deadlock can arise if the following four conditions hold
simultaneously (Necessary Conditions)
• Mutual Exclusion: Two or more resources are non-
shareable (Only one process can use at a time)
• Hold and Wait: A process is holding at least one
resource and waiting for resources.
• No Preemption: A resource cannot be taken from a
process unless the process releases the resource.
• Circular Wait: A set of processes are waiting for each
other in circular form.
Understanding Conditions for Deadlock
Mutual Exclusion: When two people meet in the landings, they
can’t just walk through because there is space only for one
person. This condition allows only one person (or process) to
use the step between them (or the resource) is the first
condition necessary for the occurrence of the deadlock.
Hold and Wait: When the two people refuse to retreat and hold
their ground, it is called holding. This is the next necessary
condition for deadlock.
No Preemption: For resolving the deadlock one can simply
cancel one of the processes for other to continue. But the
Operating System doesn’t do so. It allocates the resources to
the processors for as much time as is needed until the task is
completed. Hence, there is no temporary reallocation of the
resources. It is the third condition for deadlock.
Circular Wait: When the two people refuse to retreat and wait
for each other to retreat so that they can complete their task, it
is called circular wait. It is the last condition for deadlock to
occur.
Resource-Allocation Graph
• In RAG vertices are two type –
• 1. Process vertex – Every process will be represented as a process vertex. Generally, the
process will be represented with a circle.
• 2. Resource vertex – Every resource will be represented as a resource vertex. It represents as a
box, inside the box, there will be one dot. So the number of dots indicate how many instances
are present of each resource type.
• A set of vertices V and a set of edges E. V is partitioned into two types:
• P = {P1, P2, …, Pn}, the set consisting of all the processes in the system
• R = {R1, R2, …, Rm}, the set consisting of all resource types in the system
• request edge – directed edge Pi  Rj
• assignment edge – directed edge Rj  Pi
Example of a Resource Allocation Graph
With A Deadlock With A Cycle But
No Deadlock
• If graph contains no cycles :
• no deadlock
• If graph contains a cycle :
• if only one instance per
resource type, then
deadlock
• if several instances per
resource type, possibility
of deadlock
Methods for Handling Deadlocks
• Two ways to ensure that the system will never enter a deadlock state:
• Deadlock prevention
• Deadlock avoidance
• System is in safe state if there exists a sequence <P1,
P2, …, Pn> of ALL the processes in the systems such
that for each Pi, the resources that Pi can still request
can be satisfied by
currently available resources + resources held by
all the Pj, with j < I
That is:
• If Pi resource needs are not immediately available,
then Pi can wait until all Pj have finished
• When Pj is finished, Pi can obtain needed resources,
execute, return allocated resources, and terminate
• When Pi terminates, Pi+1 can obtain its needed
resources, and so on
Deadlock avoidance
• Single instance of a resource type
• Use a resource-allocation graph
• Multiple instances of a resource type
• Use the banker’s algorithm
Banker’s Algorithm
• 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.
• Let n = number of processes, and m = number of resources types.
• Available: Vector of length m. If available [j] = k, there are k instances of resource
type Rj available
• Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k
instances of resource type Rj
• Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k
instances of Rj
• Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to
complete its task
Need [i,j] = Max[i,j] – Allocation [i,j]
Banker’s Algorithm
• Banker’s algorithm consists of
1. Safety algorithm and
2. Resource request algorithm
• Safety Algorithm: The algorithm for finding out
whether or not a system is in a safe state
can be described as follows:
1) Let Work and Finish be vectors of length
‘m’ and ‘n’ respectively.
Initialize: Work = Available
Finish[i] = false; for i=1, 2, 3, 4….n
2) Find an i such that both
a) Finish[i] = false
b) Needi <= Work
if no such i exists goto step (4)
3) Work = Work + Allocation[i]
Finish[i] = true
goto step (2)
4) if Finish [i] = true for all i
then the system is in a safe state
• Resource-Request Algorithm : Let Requesti be the request
array for process Pi. Requesti [j] = k means process Pi
wants k instances of resource type Rj. When a request for
resources is made by process Pi, the following actions are
taken:
1) If Requesti <= Needi
Goto step (2) ; otherwise, raise an error condition,
since the process has exceeded its maximum claim.
2) If Requesti <= Available
Goto step (3); otherwise, Pi must wait, since the
resources are not available.
3) Have the system pretend to have allocated the requested
resources to process Pi by modifying the state as
follows:
• Available = Available – Requesti
• Allocationi = Allocationi + Requesti
• Needi = Needi– Requesti
Bankers Algorithm Example 1
• Consider the following snapshot of a system-
• 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?
Bankers Algorithm Example
Process Allocation Max Available Need
A B C D 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 0 0 0 0
P1 1 0 0 0 1 7 5 0 1 5 3 2 0 7 5 0
P2 1 3 5 4 2 3 5 6 1 5 3 2 1 0 0 2
P3 0 6 3 2 0 6 5 2 2 8 8 6 0 0 2 0
P4 0 0 1 4 0 6 5 6 2 14 11 8 0 6 4 2
P1 1 0 0 0 1 7 5 0 2 14 12 12 0 7 5 0
• Step 1-Need =Max-Allocation, make a matrix of need column.(Written in green below)
• Step 2-Check Need <= Available (check individual variables of both corresponding columns).
• If available < need then write same available as in last row. For example for P1- Need B(7)> Available B(5)
(See in red) and so system is not in safe state.
• If Available > Need then write next Process availability as:
• Available= Available + Allocation (written in yellow)
• So safe sequence is (P0,P2,P3,P4,P0)
Bankers Algorithm Example 1
• Step3 : To Check if a request from process P1 arrives for (0,4,2,0), can the request be granted
immediately
• Compare Given Allocation with Corresponding Need: For P1 (0,4,2,0)< (0,7,5,0)
• Compare Given Allocation with Corresponding Available: For P1 (0,4,2,0) <(1,5,2,0)
• So new Available= (1,5,2,0)-(0,4,2,0)=(1,1,0,0)
• And so new Allocation= (1,0,0,0)+(0,4,2,0)=(1,4,2,0)
• And so new need for P1=(0,7,5,0) – (0,4,2,0) =(0,3,3,0)
• Now replace the previous values of process P1 with new values:
Process Allocation Max Available Need
A B C D A B C D A B C D A B C D
P0 0 0 1 2 0 0 1 2 1 1 0 0 0 0 0 0
P1 1 4 2 0 1 7 5 0 0 3 3 0
P2 1 3 5 4 2 3 5 6 1 0 0 2
P3 0 6 3 2 0 6 5 2 0 0 2 0
P4 0 0 1 4 0 6 5 6 0 6 4 2
• Step 4: Now repeat Step1 t- Step 2 and find safe sequence.
Bankers Algorithm Example 2
• Consider a system with five processes Po through P4 and three resource types A,
B, and C. Resource type A has 10 instances, resource type B has 5 instances, and
resource type C has 7 instances. Suppose that, at time T0 , the following
snapshot of the system has been taken:
Solution:
Available instances of A = Total – Allocated = 10 –
(0+2+3+2+0) = 3
Similarly, Available instances of B = Total – Allocated = 5
– (1+0+0+1+0) = 3
Finally, Available instances of C = Total – Allocated = 7 –
(0+0+2+1+2) = 2
Next, Calculate Need by using the formula
Need = Max – Allocation
………………………A B C
Need for P0 = 7 4 3
Bankers Algorithm Example 2
• Now find out any process whose Need can
be satisfied with Available. P1 is one such
process. So, Add P1 to safe sequence <P1>.
• Update the Available by using formula
Available = Available + Allocation of
process added to safe sequence (P1)
So, new Available is 5 3 2
• Next, find out another process whose Need
is less than the updated Available i.e., 5 3 2.
P3 is one such process. Hence, Add P3
to safe sequence <P1, P3>.
• Now, Update Available by adding Allocation
of P3 to current Available.
• Proceed in the same manner. If all the
process can be added to the safe sequence
then the system is in safe state otherwise
not.
Bankers Algorithm Example 3
• Considering a system with five processes P0 through P4 and three resources of
type A, B, C. Resource type A has 10 instances, B has 5 instances and type C has
7 instances. Suppose at time t0 following snapshot of the system has been
taken:
A) What will be the content of the Need matrix?
Need [i, j] = Max [i, j] – Allocation [i, j]
Bankers Algorithm Example 3
• Is the system in a safe state? If Yes, then what is the safe sequence?
Bankers Algorithm Example 3
• What will happen if process P1 requests one additional instance of resource type
A and two instances of resource type C?
Bankers Algorithm Example 3

More Related Content

PPTX
Quality and productivity factors
PPTX
Threads (operating System)
PPTX
Branching statements
PPTX
Structure of the page table
PPTX
Blockchain Technology ppt project.pptx
PPTX
comparison of CRD, RBD and LSD
PPTX
rural development programmes in india
PPTX
Ujjwala yojna
Quality and productivity factors
Threads (operating System)
Branching statements
Structure of the page table
Blockchain Technology ppt project.pptx
comparison of CRD, RBD and LSD
rural development programmes in india
Ujjwala yojna

What's hot (20)

PPTX
Deadlock Prevention
PDF
Daa notes 1
PPTX
Code Optimization
PDF
Target language in compiler design
PPTX
Macro Processor
PPTX
Deadlocks in operating system
PPTX
Model Based Software Architectures
PDF
Deadlock in Distributed Systems
PDF
Run time storage
PDF
Measures of query cost
PPTX
Problem solving agents
PPT
Message authentication
 
PPTX
DeadLock in Operating-Systems
PPTX
PPTX
Page replacement algorithms
PPTX
Implementation of lexical analyser
PPT
Deadlock
PPT
deadlock avoidance
PPT
Risk management(software engineering)
PPTX
Bankers algorithm
Deadlock Prevention
Daa notes 1
Code Optimization
Target language in compiler design
Macro Processor
Deadlocks in operating system
Model Based Software Architectures
Deadlock in Distributed Systems
Run time storage
Measures of query cost
Problem solving agents
Message authentication
 
DeadLock in Operating-Systems
Page replacement algorithms
Implementation of lexical analyser
Deadlock
deadlock avoidance
Risk management(software engineering)
Bankers algorithm
Ad

Similar to OS - Unit 3 Deadlock (Bankers Algorithm).pptx (20)

PPT
14th November - Deadlock Prevention, Avoidance.ppt
PDF
Deadlocks Part- II.pdf
PPT
Deadlock
PPT
deadlock part5 unit 2.ppt
PDF
Deadlocks Part- III.pdf
PPTX
Deadlock in Real Time operating Systempptx
PPTX
Deadlock in Operating system concept, Types of Deadlock
PPTX
Deadlock in Operating SystemSystem Model Deadlock Characterization
PDF
Ch7 deadlocks
PPTX
Chapter 6 - Operating System Deadlock.pptx
PDF
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
PPTX
Methods for handling deadlock
PPTX
Module 3 Deadlocks.pptx
PDF
Deadlock
PDF
CH07.pdf
PPT
Deadlock principles in operating systems
PPT
Module-2Deadlock.ppt
PPT
Ch07 deadlocks
PPTX
deadlocks.pptx
14th November - Deadlock Prevention, Avoidance.ppt
Deadlocks Part- II.pdf
Deadlock
deadlock part5 unit 2.ppt
Deadlocks Part- III.pdf
Deadlock in Real Time operating Systempptx
Deadlock in Operating system concept, Types of Deadlock
Deadlock in Operating SystemSystem Model Deadlock Characterization
Ch7 deadlocks
Chapter 6 - Operating System Deadlock.pptx
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
Methods for handling deadlock
Module 3 Deadlocks.pptx
Deadlock
CH07.pdf
Deadlock principles in operating systems
Module-2Deadlock.ppt
Ch07 deadlocks
deadlocks.pptx
Ad

Recently uploaded (20)

PPTX
AI-Reporting for Emerging Technologies(BS Computer Engineering)
PDF
electrical machines course file-anna university
PDF
Micro 4 New.ppt.pdf a servay of cells and microorganism
PDF
Mechanics of materials week 2 rajeshwari
PDF
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
PDF
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
PDF
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
PPTX
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
PPTX
chapter 1.pptx dotnet technology introduction
PPTX
MAD Unit - 3 User Interface and Data Management (Diploma IT)
PDF
Unit1 - AIML Chapter 1 concept and ethics
PDF
IAE-V2500 Engine for Airbus Family 319/320
PPTX
Wireless sensor networks (WSN) SRM unit 2
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
Environmental studies, Moudle 3-Environmental Pollution.pptx
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
PPTX
CS6006 - CLOUD COMPUTING - Module - 1.pptx
PDF
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
DOCX
An investigation of the use of recycled crumb rubber as a partial replacement...
PPTX
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
AI-Reporting for Emerging Technologies(BS Computer Engineering)
electrical machines course file-anna university
Micro 4 New.ppt.pdf a servay of cells and microorganism
Mechanics of materials week 2 rajeshwari
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
chapter 1.pptx dotnet technology introduction
MAD Unit - 3 User Interface and Data Management (Diploma IT)
Unit1 - AIML Chapter 1 concept and ethics
IAE-V2500 Engine for Airbus Family 319/320
Wireless sensor networks (WSN) SRM unit 2
Cryptography and Network Security-Module-I.pdf
Environmental studies, Moudle 3-Environmental Pollution.pptx
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
CS6006 - CLOUD COMPUTING - Module - 1.pptx
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
An investigation of the use of recycled crumb rubber as a partial replacement...
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj

OS - Unit 3 Deadlock (Bankers Algorithm).pptx

  • 2. Unit 3 CPU Scheduling: 1. Scheduling Concepts, 2. Performance Criteria, 3. Process States, 4. Process Transition Diagram, 5. Schedulers, 6. Process Control Block (PCB), 7. Process address space, 8. Process identification information, 9. Threads and their management, 10. Scheduling Algorithms, 11. Multiprocessor Scheduling. Deadlock: 1. System model, 2. Deadlock characterization, 3. Prevention, 4. Avoidance and detection, 5. Recovery from deadlock.
  • 3. Deadlock : System model • Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. • Consider an example when two trains are coming toward each other on the same track and there is only one track, none of the trains can move once they are in front of each other. • Deadlock can arise if the following four conditions hold simultaneously (Necessary Conditions) • Mutual Exclusion: Two or more resources are non- shareable (Only one process can use at a time) • Hold and Wait: A process is holding at least one resource and waiting for resources. • No Preemption: A resource cannot be taken from a process unless the process releases the resource. • Circular Wait: A set of processes are waiting for each other in circular form.
  • 4. Understanding Conditions for Deadlock Mutual Exclusion: When two people meet in the landings, they can’t just walk through because there is space only for one person. This condition allows only one person (or process) to use the step between them (or the resource) is the first condition necessary for the occurrence of the deadlock. Hold and Wait: When the two people refuse to retreat and hold their ground, it is called holding. This is the next necessary condition for deadlock. No Preemption: For resolving the deadlock one can simply cancel one of the processes for other to continue. But the Operating System doesn’t do so. It allocates the resources to the processors for as much time as is needed until the task is completed. Hence, there is no temporary reallocation of the resources. It is the third condition for deadlock. Circular Wait: When the two people refuse to retreat and wait for each other to retreat so that they can complete their task, it is called circular wait. It is the last condition for deadlock to occur.
  • 5. Resource-Allocation Graph • In RAG vertices are two type – • 1. Process vertex – Every process will be represented as a process vertex. Generally, the process will be represented with a circle. • 2. Resource vertex – Every resource will be represented as a resource vertex. It represents as a box, inside the box, there will be one dot. So the number of dots indicate how many instances are present of each resource type. • A set of vertices V and a set of edges E. V is partitioned into two types: • P = {P1, P2, …, Pn}, the set consisting of all the processes in the system • R = {R1, R2, …, Rm}, the set consisting of all resource types in the system • request edge – directed edge Pi  Rj • assignment edge – directed edge Rj  Pi
  • 6. Example of a Resource Allocation Graph With A Deadlock With A Cycle But No Deadlock • If graph contains no cycles : • no deadlock • If graph contains a cycle : • if only one instance per resource type, then deadlock • if several instances per resource type, possibility of deadlock
  • 7. Methods for Handling Deadlocks • Two ways to ensure that the system will never enter a deadlock state: • Deadlock prevention • Deadlock avoidance • System is in safe state if there exists a sequence <P1, P2, …, Pn> of ALL the processes in the systems such that for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < I That is: • If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished • When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate • When Pi terminates, Pi+1 can obtain its needed resources, and so on
  • 8. Deadlock avoidance • Single instance of a resource type • Use a resource-allocation graph • Multiple instances of a resource type • Use the banker’s algorithm
  • 9. Banker’s Algorithm • 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. • Let n = number of processes, and m = number of resources types. • Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available • Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj • Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj • Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task Need [i,j] = Max[i,j] – Allocation [i,j]
  • 10. Banker’s Algorithm • Banker’s algorithm consists of 1. Safety algorithm and 2. Resource request algorithm • Safety Algorithm: The algorithm for finding out whether or not a system is in a safe state can be described as follows: 1) Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively. Initialize: Work = Available Finish[i] = false; for i=1, 2, 3, 4….n 2) Find an i such that both a) Finish[i] = false b) Needi <= Work if no such i exists goto step (4) 3) Work = Work + Allocation[i] Finish[i] = true goto step (2) 4) if Finish [i] = true for all i then the system is in a safe state • Resource-Request Algorithm : Let Requesti be the request array for process Pi. Requesti [j] = k means process Pi wants k instances of resource type Rj. When a request for resources is made by process Pi, the following actions are taken: 1) If Requesti <= Needi Goto step (2) ; otherwise, raise an error condition, since the process has exceeded its maximum claim. 2) If Requesti <= Available Goto step (3); otherwise, Pi must wait, since the resources are not available. 3) Have the system pretend to have allocated the requested resources to process Pi by modifying the state as follows: • Available = Available – Requesti • Allocationi = Allocationi + Requesti • Needi = Needi– Requesti
  • 11. Bankers Algorithm Example 1 • Consider the following snapshot of a system- • 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?
  • 12. Bankers Algorithm Example Process Allocation Max Available Need A B C D 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 0 0 0 0 P1 1 0 0 0 1 7 5 0 1 5 3 2 0 7 5 0 P2 1 3 5 4 2 3 5 6 1 5 3 2 1 0 0 2 P3 0 6 3 2 0 6 5 2 2 8 8 6 0 0 2 0 P4 0 0 1 4 0 6 5 6 2 14 11 8 0 6 4 2 P1 1 0 0 0 1 7 5 0 2 14 12 12 0 7 5 0 • Step 1-Need =Max-Allocation, make a matrix of need column.(Written in green below) • Step 2-Check Need <= Available (check individual variables of both corresponding columns). • If available < need then write same available as in last row. For example for P1- Need B(7)> Available B(5) (See in red) and so system is not in safe state. • If Available > Need then write next Process availability as: • Available= Available + Allocation (written in yellow) • So safe sequence is (P0,P2,P3,P4,P0)
  • 13. Bankers Algorithm Example 1 • Step3 : To Check if a request from process P1 arrives for (0,4,2,0), can the request be granted immediately • Compare Given Allocation with Corresponding Need: For P1 (0,4,2,0)< (0,7,5,0) • Compare Given Allocation with Corresponding Available: For P1 (0,4,2,0) <(1,5,2,0) • So new Available= (1,5,2,0)-(0,4,2,0)=(1,1,0,0) • And so new Allocation= (1,0,0,0)+(0,4,2,0)=(1,4,2,0) • And so new need for P1=(0,7,5,0) – (0,4,2,0) =(0,3,3,0) • Now replace the previous values of process P1 with new values: Process Allocation Max Available Need A B C D A B C D A B C D A B C D P0 0 0 1 2 0 0 1 2 1 1 0 0 0 0 0 0 P1 1 4 2 0 1 7 5 0 0 3 3 0 P2 1 3 5 4 2 3 5 6 1 0 0 2 P3 0 6 3 2 0 6 5 2 0 0 2 0 P4 0 0 1 4 0 6 5 6 0 6 4 2 • Step 4: Now repeat Step1 t- Step 2 and find safe sequence.
  • 14. Bankers Algorithm Example 2 • Consider a system with five processes Po through P4 and three resource types A, B, and C. Resource type A has 10 instances, resource type B has 5 instances, and resource type C has 7 instances. Suppose that, at time T0 , the following snapshot of the system has been taken: Solution: Available instances of A = Total – Allocated = 10 – (0+2+3+2+0) = 3 Similarly, Available instances of B = Total – Allocated = 5 – (1+0+0+1+0) = 3 Finally, Available instances of C = Total – Allocated = 7 – (0+0+2+1+2) = 2 Next, Calculate Need by using the formula Need = Max – Allocation ………………………A B C Need for P0 = 7 4 3
  • 15. Bankers Algorithm Example 2 • Now find out any process whose Need can be satisfied with Available. P1 is one such process. So, Add P1 to safe sequence <P1>. • Update the Available by using formula Available = Available + Allocation of process added to safe sequence (P1) So, new Available is 5 3 2 • Next, find out another process whose Need is less than the updated Available i.e., 5 3 2. P3 is one such process. Hence, Add P3 to safe sequence <P1, P3>. • Now, Update Available by adding Allocation of P3 to current Available. • Proceed in the same manner. If all the process can be added to the safe sequence then the system is in safe state otherwise not.
  • 16. Bankers Algorithm Example 3 • Considering a system with five processes P0 through P4 and three resources of type A, B, C. Resource type A has 10 instances, B has 5 instances and type C has 7 instances. Suppose at time t0 following snapshot of the system has been taken: A) What will be the content of the Need matrix? Need [i, j] = Max [i, j] – Allocation [i, j]
  • 17. Bankers Algorithm Example 3 • Is the system in a safe state? If Yes, then what is the safe sequence?
  • 18. Bankers Algorithm Example 3 • What will happen if process P1 requests one additional instance of resource type A and two instances of resource type C?