- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- Process Management
- Operating System Processes
- Process Control Block
- Operations on Processes
- Inter Process Communication
- Context Switching
- Multi-threading
- Scheduling Algorithms
- Process Scheduling
- Preemptive and Non-Preemptive Scheduling
- Scheduling Algorithms Overview
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithm
- HRRN Scheduling Algorithm
- Priority Scheduling Algorithm
- Multilevel Queue Scheduling
- Lottery Scheduling Algorithm
- Turn Around Time & Waiting Time
- Burst Time in SJF Scheduling
- Process Synchronization
- Process Synchronization
- Critical Section Problem
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Semaphores
- Counting Semaphores
- Mutex
- Turn Variable
- Bounded Buffer Problem
- Reader Writer Locks
- Test and Set Lock
- Peterson's Solution
- Monitors
- Sleep and Wake
- Race Condition
- OS Deadlock
- Introduction to Deadlock
- Conditions for Deadlock
- Deadlock Handling
- Deadlock Prevention
- Deadlock Avoidance (Banker's Algorithm)
- Deadlock Detection and Recovery
- Deadlock Ignorance
- Memory Management
- Memory Management
- Contiguous Memory Allocation
- Non-Contiguous Memory Allocation
- First Fit Algorithm
- Next Fit Algorithm
- Best Fit Algorithm
- Worst Fit Algorithm
- Fragmentation
- Virtual Memory
- Segmentation
- Buddy System
- Slab Allocation
- Overlays
- Paging and Page Replacement
- Paging
- Demand Paging
- Page Table
- Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Belady's Anomaly
- Thrashing
- Storage and File Management
- File Systems
- File Attributes
- Structures of Directory
- Linked Index Allocation
- Indexed Allocation
- Disk Scheduling Algorithms
- FCFS Disk Scheduling
- SSTF Disk Scheduling
- SCAN Disk Scheduling
- LOOK Disk Scheduling
- I/O Systems
- I/O Hardware
- I/O Software
- OS Types
- OS - Types
- OS - Batch Processing
- OS - Multiprocessing
- OS - Hybrid
- OS - Monolithic
- OS - Zephyr
- OS - Nix
- OS - Linux
- OS - Blackberry
- OS - Garuda
- OS - Tails
- OS - Clustered
- OS - Haiku
- OS - AIX
- OS - Solus
- OS - Tizen
- OS - Bharat
- OS - Fire
- OS - Bliss
- OS - VxWorks
- OS - Embedded
- OS - Single User
- Miscellaneous Topics
- OS - Security
- OS Questions Answers
- OS - Questions Answers
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Conditions for Deadlock in Operating System
A deadlock in an operating system is a condition where a group of processes get stuck in a state where no process in the group can proceed forward. Such a situation occurs when each process is waiting for a resource that another process in the group holds, creating a cycle of waiting where no process can continue its execution. Essentially, the processes are deadlocked because they cannot release the resources they need to continue.
Conditions for Deadlock in Operating System
In an operating system, a deadlock occurs when a set of processes are blocked, each waiting for a resource held by another process in the set, leading to a situation where no process can proceed.
For a deadlock to happen, certain conditions must be met. These conditions are commonly referred to as the deadlock conditions and are based on the Coffman conditions, which describe the necessary circumstances for a deadlock to occur.
Mutual Exclusion
Mutual Exclusion is a condition that states to occur deadlock in an operating system, at least one resource must be held in a non-shareable mode, meaning that only one process can use that resource at any given time. If another process requests the same resource, it must wait for the resource to be released.
For example, a printer is a non-shareable resource only one process can print at a time. When the chrome browser is using the printer to print a page, the PDF viewer must wait for the printer to be released before it can print its document.
Hold and Wait
Hold and Wait is a condition that occurs when a process holding at least one resource is waiting to acquire additional resources that are currently being held by other processes. This means that a process that already has resources may request more resources, which it cannot obtain because they are held by other processes.
The image show a scenario of Hold and Wait happening between a printer and a scanner.
Here, Process A holds a printer and waits for a scanner, while Process B holds a scanner and waits for the printer. Both processes are holding resources and waiting for resources held by the other process, leading to a potential deadlock situation.
No Preemption
No Preemption is a condition that states resources cannot be forcibly taken away from a process holding them. A process must release the resource voluntarily when it is no longer needed. If a process is holding a resource and is waiting for another resource, it cannot be preempted (i.e., it cannot be forced to release the resource until it finishes its task).
For example, if Process A is holding a printer and is waiting for a scanner, the system cannot force Process A to give up the printer. Process A must release the printer voluntarily once it has completed its task.
Circular Wait
Circular Wait is a condition where a set of processes exist such that each process in the set is waiting for a resource that another process in the set holds, forming a cycle of dependencies. In other words, there is a circular chain of processes where each process is waiting for a resource held by the next process in the chain.
For example, Process A waits for a resource held by Process B, Process B waits for a resource held by Process C, and Process C waits for a resource held by Process A, forming a cycle of waiting processes.
How to Avoid Deadlocks?
To avoid deadlock, the operating system can take measures to prevent one or more of the four necessary conditions from occurring. This can be done in the following ways −
- Prevent Mutual Exclusion − This is generally not feasible because many resources (like printers, files, or memory) must be used exclusively by one process at a time. However, for some resources (like read-only resources), multiple processes can access them simultaneously.
- Prevent Hold and Wait − Require processes to request all resources they will need at once before starting execution. This is called the "all-or-nothing" approach. Another option is to require processes to release all the resources they currently hold before requesting new ones.
- Prevent No Preemption − Allow preemption of resources. If a process holding some resources is waiting for additional resources, the operating system can preempt the resources currently held by the process and assign them to other processes.
Conclusion
In the next few chapters, we will explain in detail the conditions that lead to a deadlock state, how to detect and recover from a deadlock, and also how to take the required precautionary measures to prevent the system from getting into a deadlock state.