Embed presentation

![GROUP: MOUNTAIN OFLIGHT MD. Saidur Rahman Kohinoor [142-15-3669] Md. Mudasser-ul Haque [142-15-3688] Obaidul Hassan [142-15-3559] Israt ZaHan Esha [142-15-3604] Md. Hamia [142-15-3458]2](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-2-2048.jpg&f=jpg&w=240)

![WHAT IS DEADLOCK?o An example from US Kansas law:o “When two trains approach each other at acrossing, both shall come to a full stop andneither shall start up again until the otherhas gone.”4[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-4-2048.jpg&f=jpg&w=240)
![REAL WORLDDEADLOCKS!5• Truck A has to waitfor truck B tomove• Notdeadlocked[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-5-2048.jpg&f=jpg&w=240)
![REAL WORLD DEADLOCKS!6Neither truck can proceed[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-6-2048.jpg&f=jpg&w=240)
![GRAPH WITHOUT ADEADLOCK7R1P1P2P3R2P4[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-7-2048.jpg&f=jpg&w=240)
![GRAPH WITH A DEADLOCK8R1P1 P2 P3R3R2R4[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-8-2048.jpg&f=jpg&w=240)
![DEALING WITH DEADLOCKSo Stop a deadlock ever occuringo deadlock preventiono disallow at least one of the necessaryconditionso deadlock avoidanceo see a deadlock coming and alter theprocess/resource allocation strategy9continued[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-9-2048.jpg&f=jpg&w=240)
![ Deadlock detection and recovery Ignore the problemdone by most OS, including UNIXcheap solutioninfrequent, manual reboots may beacceptable10[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-10-2048.jpg&f=jpg&w=240)
![DEADLOCK PREVENTION Eliminate one (or more) of:mutual exclusionhold and waitno preemption (i.e. have preemption)circular wait11[142-15-3688]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-11-2048.jpg&f=jpg&w=240)
![ELIMINATE MUTUALEXCLUSION Shared resources do not require mutualexclusione.g. read-only files But some resources cannot be shared (at thesame time)e.g. printers12[142-15-3688]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-12-2048.jpg&f=jpg&w=240)
![DEADLOCK AVOIDANCE In deadlock avoidance, the necessaryconditions are untouched. Instead, extra information about resources isused by the OS to do better forward planningof process/resource allocationindirectly avoids circular wait13[142-15-3688]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-13-2048.jpg&f=jpg&w=240)
![SAFE STATES• An OS is in a safe state if there is asafe sequence of process executions<P1, P2, …, Pn>.• A safe state cannot lead to deadlock.• An unsafe state may lead to deadlock.• Deadlock is avoided by always keepingthe system in a safe state– this may reduce resource utilization 14DeadlockUnsafeSafe[142-15-3559]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-14-2048.jpg&f=jpg&w=240)
![EXAMPLE 1 Max no. of resources: 12 tape drives Max needs Current AllocationP0 10 5P1 4 2P2 9 2 Currently, there are 3 free tape drives The OS is in a safe state, since <P1, P0, P2> is asafe sequence.15[142-15-3559]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-15-2048.jpg&f=jpg&w=240)
![EXAMPLE 2 Same as last slide, but P2 now has 4 tapedrives allocated currently. Max needs Current AllocationP0 10 5P1 4 2P2 9 4 The OS is in an unsafe state.16[142-15-3559]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-16-2048.jpg&f=jpg&w=240)
![BANKER’S ALGORITHM Assume that:a resource can have multiple instancesthe OS has N processes, M resource types Initially, each process must declare themaximum no. of resources it will need. Calculate a safe sequence if possible.17[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-17-2048.jpg&f=jpg&w=240)
![WAIT-FOR GRAPH• Assume that each resource has only oneinstance.• Create a wait-for graph by removing theresource types nodes from a resource allocationgraph.• Deadlock exists if and only if the wait-for graphcontains a cycle.18[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-18-2048.jpg&f=jpg&w=240)
![EXAMPLE19R1P2R3 R4R2 R5P1 P3P5P4P2P1 P3P5P4[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-19-2048.jpg&f=jpg&w=240)
![BANKER’S ALGORITHMVARIATION If a resource type can have multiple instances,then an algorithm very similar to the banker’salgorithm can be used. The algorithm investigates every possibleallocation sequence for the processes thatremain to be completed.20[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-20-2048.jpg&f=jpg&w=240)
![EXAMPLE Resource Type InstancesA 7B 2C 621continued[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-21-2048.jpg&f=jpg&w=240)
![Allocation Request AvailableA B C A B C A B CP0 0 1 0 0 0 0 0 0 0P1 2 0 0 2 0 2P2 3 0 3 0 0 0P3 2 1 1 1 0 0P4 0 0 2 0 0 2 The OS is not in a deadlocked state since<P0, P2, P3, P1, P4> is a safe sequence.22[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-22-2048.jpg&f=jpg&w=240)
![EXAMPLE 2 Change P2 to request 1 C instance23AllocationAllocation RequestRequest AvailableAvailableA B CA B C A B CA B C A B CA B CPP00 0 1 00 1 0 0 0 00 0 0 0 0 00 0 0PP11 2 0 02 0 0 2 0 22 0 2PP22 3 0 33 0 3 0 00 0 11PP33 2 1 12 1 1 1 0 01 0 0PP44 0 0 20 0 2 0 0 20 0 2The OSThe OS isis deadlocked.deadlocked.[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-23-2048.jpg&f=jpg&w=240)
![DEADLOCK RECOVERY Tell the operator System-based recovery:abort one or more processes in the circularwaitpreempt resources in one or more deadlockedprocesses24[142-15-3458]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-24-2048.jpg&f=jpg&w=240)
![PROCESS TERMINATION Abort all deadlocked processes, or Abort one process at a time until thedeadlocked cycle disappearsnot always easy to abort a processchoice should be based on minimum cost25[142-15-3458]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-25-2048.jpg&f=jpg&w=240)
![RESOURCE PREEMPTION Issues:how to select a resource(e.g. by using minimum cost)how to rollback the process which has justlost its resourcesavoiding process starvation26[142-15-3458]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-26-2048.jpg&f=jpg&w=240)



The document discusses the concept of deadlock in operating systems, providing definitions and examples, including a real-world analogy with trains. It outlines methods for deadlock prevention, avoidance, detection, and recovery, as well as the use of the Banker's algorithm for safe resource allocation. Various examples are presented to illustrate safe and unsafe states in resource allocation scenarios.

![GROUP: MOUNTAIN OFLIGHT MD. Saidur Rahman Kohinoor [142-15-3669] Md. Mudasser-ul Haque [142-15-3688] Obaidul Hassan [142-15-3559] Israt ZaHan Esha [142-15-3604] Md. Hamia [142-15-3458]2](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-2-2048.jpg&f=jpg&w=240)

![WHAT IS DEADLOCK?o An example from US Kansas law:o “When two trains approach each other at acrossing, both shall come to a full stop andneither shall start up again until the otherhas gone.”4[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-4-2048.jpg&f=jpg&w=240)
![REAL WORLDDEADLOCKS!5• Truck A has to waitfor truck B tomove• Notdeadlocked[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-5-2048.jpg&f=jpg&w=240)
![REAL WORLD DEADLOCKS!6Neither truck can proceed[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-6-2048.jpg&f=jpg&w=240)
![GRAPH WITHOUT ADEADLOCK7R1P1P2P3R2P4[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-7-2048.jpg&f=jpg&w=240)
![GRAPH WITH A DEADLOCK8R1P1 P2 P3R3R2R4[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-8-2048.jpg&f=jpg&w=240)
![DEALING WITH DEADLOCKSo Stop a deadlock ever occuringo deadlock preventiono disallow at least one of the necessaryconditionso deadlock avoidanceo see a deadlock coming and alter theprocess/resource allocation strategy9continued[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-9-2048.jpg&f=jpg&w=240)
![ Deadlock detection and recovery Ignore the problemdone by most OS, including UNIXcheap solutioninfrequent, manual reboots may beacceptable10[142-15-3669]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-10-2048.jpg&f=jpg&w=240)
![DEADLOCK PREVENTION Eliminate one (or more) of:mutual exclusionhold and waitno preemption (i.e. have preemption)circular wait11[142-15-3688]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-11-2048.jpg&f=jpg&w=240)
![ELIMINATE MUTUALEXCLUSION Shared resources do not require mutualexclusione.g. read-only files But some resources cannot be shared (at thesame time)e.g. printers12[142-15-3688]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-12-2048.jpg&f=jpg&w=240)
![DEADLOCK AVOIDANCE In deadlock avoidance, the necessaryconditions are untouched. Instead, extra information about resources isused by the OS to do better forward planningof process/resource allocationindirectly avoids circular wait13[142-15-3688]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-13-2048.jpg&f=jpg&w=240)
![SAFE STATES• An OS is in a safe state if there is asafe sequence of process executions<P1, P2, …, Pn>.• A safe state cannot lead to deadlock.• An unsafe state may lead to deadlock.• Deadlock is avoided by always keepingthe system in a safe state– this may reduce resource utilization 14DeadlockUnsafeSafe[142-15-3559]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-14-2048.jpg&f=jpg&w=240)
![EXAMPLE 1 Max no. of resources: 12 tape drives Max needs Current AllocationP0 10 5P1 4 2P2 9 2 Currently, there are 3 free tape drives The OS is in a safe state, since <P1, P0, P2> is asafe sequence.15[142-15-3559]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-15-2048.jpg&f=jpg&w=240)
![EXAMPLE 2 Same as last slide, but P2 now has 4 tapedrives allocated currently. Max needs Current AllocationP0 10 5P1 4 2P2 9 4 The OS is in an unsafe state.16[142-15-3559]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-16-2048.jpg&f=jpg&w=240)
![BANKER’S ALGORITHM Assume that:a resource can have multiple instancesthe OS has N processes, M resource types Initially, each process must declare themaximum no. of resources it will need. Calculate a safe sequence if possible.17[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-17-2048.jpg&f=jpg&w=240)
![WAIT-FOR GRAPH• Assume that each resource has only oneinstance.• Create a wait-for graph by removing theresource types nodes from a resource allocationgraph.• Deadlock exists if and only if the wait-for graphcontains a cycle.18[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-18-2048.jpg&f=jpg&w=240)
![EXAMPLE19R1P2R3 R4R2 R5P1 P3P5P4P2P1 P3P5P4[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-19-2048.jpg&f=jpg&w=240)
![BANKER’S ALGORITHMVARIATION If a resource type can have multiple instances,then an algorithm very similar to the banker’salgorithm can be used. The algorithm investigates every possibleallocation sequence for the processes thatremain to be completed.20[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-20-2048.jpg&f=jpg&w=240)
![EXAMPLE Resource Type InstancesA 7B 2C 621continued[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-21-2048.jpg&f=jpg&w=240)
![Allocation Request AvailableA B C A B C A B CP0 0 1 0 0 0 0 0 0 0P1 2 0 0 2 0 2P2 3 0 3 0 0 0P3 2 1 1 1 0 0P4 0 0 2 0 0 2 The OS is not in a deadlocked state since<P0, P2, P3, P1, P4> is a safe sequence.22[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-22-2048.jpg&f=jpg&w=240)
![EXAMPLE 2 Change P2 to request 1 C instance23AllocationAllocation RequestRequest AvailableAvailableA B CA B C A B CA B C A B CA B CPP00 0 1 00 1 0 0 0 00 0 0 0 0 00 0 0PP11 2 0 02 0 0 2 0 22 0 2PP22 3 0 33 0 3 0 00 0 11PP33 2 1 12 1 1 1 0 01 0 0PP44 0 0 20 0 2 0 0 20 0 2The OSThe OS isis deadlocked.deadlocked.[142-15-3604]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-23-2048.jpg&f=jpg&w=240)
![DEADLOCK RECOVERY Tell the operator System-based recovery:abort one or more processes in the circularwaitpreempt resources in one or more deadlockedprocesses24[142-15-3458]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-24-2048.jpg&f=jpg&w=240)
![PROCESS TERMINATION Abort all deadlocked processes, or Abort one process at a time until thedeadlocked cycle disappearsnot always easy to abort a processchoice should be based on minimum cost25[142-15-3458]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-25-2048.jpg&f=jpg&w=240)
![RESOURCE PREEMPTION Issues:how to select a resource(e.g. by using minimum cost)how to rollback the process which has justlost its resourcesavoiding process starvation26[142-15-3458]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fospresentationdeadlock-161213182751%2f75%2fOperating-System-Deadlock-26-2048.jpg&f=jpg&w=240)


Introduction of the group and a prayer.
Definition of deadlock, real-world examples using trucks and law analogy.
Graphs illustrating scenarios with and without deadlock.
Strategies for dealing with deadlocks, including prevention, avoidance, detection, and recovery.
Techniques to prevent deadlocks by eliminating mutual exclusion and other conditions.
Deadlock avoidance by maintaining a safe state and examples showing safe/unsafe sequences.
The Banker’s Algorithm for allocation and management of resources to prevent deadlocks.
Examples illustrating safe sequences and the impact of additional resource requests.
Methods for recovering from deadlocks, including process termination and resource preemption.
Final thoughts and wrap-up on the topic of deadlocks.