










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 50
This page cannot be seen from the preview
Don't miss anything!











































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.
(^) 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.
The process which once scheduled will be executed till the completion. No other process can be scheduled by the scheduler meanwhile.
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.
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.
(^) 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.
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.
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.