
- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- OS - TAT & WAT
- OS Processes
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling Algorithms
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithms
- HRRN Scheduling Algorithms
- Priority Scheduling Algorithms
- Multilevel Queue Scheduling
- Context Switching
- Operations on Processes
- Lottery Process Scheduling
- Predicting Burst Time SJF Scheduling
- Race Condition Vulnerability
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Process Control Block
- Inter Process Communication
- Preemptive and Non-Preemptive Scheduling
- Operating System - Deadlock
- Introduction to Deadlock in Operating System
- Conditions for Deadlock in Operating System
- OS Synchronization
- Operating System - Process Synchronization
- Operating System - Critical Section
- Operating System - Semaphores
- Operating System - Counting Semaphores
- Operating System - Mutex
- Operating System - Lock Variable in Process Synchronization
- Operating System - Turn Variable in Process Synchronization
- Operating System - Bounded Buffer Problem
- Operating System - Reader Writer Locks in Process Synchronization
- Operating System - Test Set Lock in Process Synchronization
- Operating System - Peterson Solution in Process Synchronization
- Operating System - Monitors in Process Synchronization
- Operating System - Sleep and Wake in Process Synchronization
- OS Memory Management
- OS - Memory Management
- OS - Virtual Memory
- OS Storage Management
- File Systems in Operating System
- Linked Index Allocation in Operating System
- Indexed Allocation in Operating System
- Structures of Directory in Operating System
- File Attributes in Operating System
- Operating System - Page Replacement
- Operating Systems - Thrashing
- Belady’s Anomaly in Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Operating System - Types
- Types of Operating System
- Batch Processing Operating System
- Multiprocessing Operating System
- Hybrid Operating System
- Monolithic Operating System
- Zephyr Operating System
- Nix Operating System
- Blackberry Operating System
- Garuda Operating System
- Tails Operating System
- Clustered Operating System
- Haiku Operating System
- AIX Operating System
- Solus Operating system
- Tizen Operating System
- Bharat Operating System
- Fire Operating System
- Bliss Operating System
- VxWorks Operating System
- Embedded Operating System
- Single User Operating System
- OS Miscellaneous
- OS - Multi-threading
- OS - I/O Hardware
- OS - I/O Software
- OS - Security
- OS - Linux
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Introduction of Deadlock in Operating System
Deadlock in an operating system refers to a situation where a set of processes are unable to proceed because each process in the set is waiting for a resource that another process in the set holds, causing a cycle of dependency. In simpler terms, deadlock occurs when processes get stuck in a state where they are all waiting for resources that are locked by other processes in the same set, and none can proceed. This leads to the processes being unable to complete their tasks, causing system resources to be wasted.
What is a Deadlock?
Deadlock is a state in which two or more processes are unable to proceed because each is waiting for a resource that the other holds, resulting in a cycle of dependencies. The processes involved in the deadlock situation are said to be deadlocked because they cannot continue execution without intervention from the operating system.
Conditions for Deadlock
For deadlock to occur, four necessary conditions must hold simultaneously. These conditions are often referred to as the Coffman conditions, named after the researchers who defined them:
Mutual Exclusion:At least one resource must be held in a non-shareable mode, meaning only one process can use it at a time. Example: A printer can only be used by one process at a time.
Hold and Wait: A process holding at least one resource is waiting to acquire additional resources that are currently being held by other processes. Example: Process A holds a printer and waits for a scanner, while Process B holds a scanner and waits for the printer.
No Preemption: Resources cannot be forcibly taken away from processes holding them. A process must release the resource voluntarily when it is no longer needed. 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.
Circular Wait: 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. Example: Process A waits for Process Bs resource, Process B waits for Process Cs resource, and Process C waits for Process As resource, forming a circular chain.
Effects of Deadlock
System Inefficiency: Deadlock leads to the wastage of resources that are held by processes that cannot make progress.
Process Starvation: Some processes may never get the resources they need if they are involved in a deadlock.
System Unresponsiveness: The system may appear frozen or unresponsive because processes cannot complete their tasks due to deadlock.
How to prevent Deadlock
Prevention: The operating system can prevent deadlock by ensuring that at least one of the Coffman conditions is not met. For example, preventing circular wait can be done by requiring processes to request all the resources they will need at once (no hold and wait).
Avoidance: Deadlock avoidance algorithms, such as the Banker's Algorithm, dynamically analyze resource requests to ensure the system never enters a state where deadlock could occur.
Detection and Recovery: Some systems allow deadlock to occur but periodically check for it. If deadlock is detected, the system takes action to recover, such as terminating a process or forcibly preempting resources.