DeadLocks



Necessary Conditions to Deadlock to happen
- Mutual Exclusion (Only one process can use a resource at a time(No sharing))
- Hold and Wait(One process is holding a resource and waiting for another resource)
- No Preemption (No one can take the resource from the process once it is allocated)
- Circular Wait(There is a circular chain of processes where each process is waiting for another process to release a resource)
Deadlock Handling
- Deadlock Prevention
- Deadlock Avoidance
- Deadlock Detection and Recovery
- Ignore the Deadlock
Deadlock Prevention
- Mutual Exclusion: Not required for sharable resources
- Spooling: Spooling is an acronym for Simultaneous Peripheral Operations On-Line. It is a process in which data is temporarily gathered to be used and executed by a device, program or the system. Spooling helps to improve the performance of computer processing by directing data from different sources.
- like take the example of printer, if two process are printing the document, then the printer will print the document one by one, it will not print both the document at the same time.
- printer daemon will queue the document and print one by one.
- Hold and Wait: Must guarantee that whenever a process requests a resource, it does not hold any other resources.
- Ways to prevent Hold and Wait
- Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none.
- Require process to release all resources before it can request any other.
- Require process to request all resources in advance and be allocated all its resources before it begins execution.
- No Preemption: If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.
- Circular Wait: Impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration.(we do numbering of resources and then we allocate the resources in increasing order)
Deadlock Avoidance
- Deadlock avoidance requires that the operating system be given in advance additional information concerning which resources a process will request and use during its entire lifetime.
- This advance knowledge is used to decide whether the allocation of resources will leave the system in a safe state.
- Banker's Algorithm is used to check whether the system is in safe state or not.
- whenever a process request for some resources then our oprating system checks whether granting theses resources leads to deadlock or not if deadlock can occur then resource allcation will not be proceeded.
- Banker's Algorithm: used for Deadlock Avoidance and Deadlock detection.