Deadlock in Operating Systems: Causes, Prevention, and Detection, Study notes of Operating Systems

Deadlock is a situation in an operating system where two or more processes are stuck waiting for each other to release resources, resulting in a system-wide halt or indefinite delay.

Typology: Study notes

2022/2023

Uploaded on 03/26/2023

Mwero
Mwero 🇰🇪

3 documents

1 / 50

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DEADLOCK
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32

Partial preview of the text

Download Deadlock in Operating Systems: Causes, Prevention, and Detection and more Study notes Operating Systems in PDF only on Docsity!

DEADLOCK

 Every process needs some resources to complete its execution. However, the resource is granted in a sequential order.  The process requests for some resource.  OS grant the resource if it is available otherwise let the process waits.  The process uses it and release on the completion.

Introduction to Deadlock

 (^) After some time, P1 demands for R2 which is being used by P2.  (^) P1 halts its execution since it can't complete without R2.  (^) P2 also demands for R3 which is being used by P3.  (^) P2 also stops its execution because it can't continue without R3.  (^) P3 also demands for R1 which is being used by P therefore P3 also stops its execution.  (^) In this scenario, a cycle is being formed among the three processes.  (^) None of the process is progressing and they are all waiting.  (^) The computer becomes unresponsive since all the processes got blocked.

Necessary conditions for Deadlocks

 A resource can only be shared in mutually exclusive manner.  It implies, if two process cannot use the same resource at the same time.

1.Mutual Exclusion

 The process which once scheduled will be executed till the completion.  No other process can be scheduled by the scheduler meanwhile.

3.No preemption

 All the processes must be waiting for the resources in a cyclic manner so that the last process is waiting for the resource which is being held by the first process.

4.Circular Wait

 Deadlock Ignorance is the most widely used approach among all the mechanism.  This is being used by many operating systems mainly for end user uses.  In this approach, the Operating system assumes that deadlock never occurs.  It simply ignores deadlock.  This approach is best suitable for a single end user system where User uses the system only for browsing and all other normal stuff.

1.Deadlock Ignorance

 (^) There is always a tradeoff between Correctness and performance.  The operating systems like Windows and Linux mainly focus upon performance.  (^) However, the performance of the system decreases if it uses deadlock handling mechanism all the time if deadlock happens 1 out of 100 times then it is completely unnecessary to use the deadlock handling mechanism all the time.  (^) In these types of systems, the user has to simply restart the computer in the case of deadlock.  Windows and Linux are mainly using this approach.

 In deadlock avoidance, the operating system checks whether the system is in safe state or in unsafe state at every step which the operating system performs.  The process continues until the system is in safe state.  Once the system moves to unsafe state, the OS has to backtrack one step.  In simple words, The OS reviews each allocation so that the allocation doesn't cause the deadlock in the system.

3.Deadlock avoidance

 This approach lets the processes fall in deadlock and then periodically check whether deadlock occur in the system or not.  If it occurs then it applies some of the recovery methods to the system to get rid of deadlock.

4.Deadlock detection and recovery

 Let's see how we can prevent each of the conditions.

 Mutual exclusion from the resource point of view is the fact that a resource can never be used by more than one process simultaneously which is fair enough but that is the main reason behind the deadlock.  If a resource could have been used by more than one process at the same time then the process would have never been waiting for any resource.  However, if we can be able to violate resources behaving in the mutually exclusive manner then the deadlock can be prevented.

1. Eliminate Mutual Exclusion