Deadlocks

Operating Systems Part 7

ยท

3 min read

Deadlocks

Deadlocks

  • If two or more processes are waiting for happening of some event, which never happens, then we say that these processes are involved in a state that is called deadlock.
  • Two processes mutually waiting for an event, which never happens, this state is called deadlock.

4 necessary conditions for deadlock

  1. Mutual Exclusion.
  2. No Pre-emption.
  3. Hold & Wait.
  4. Circular Wait.

Resource Allocation Graph(RAG)

To represent how the resources are allocated to processes, assigned multiple resources, RAG is used. Two types - Single Instance RAG & Multiple Instance RAG.

Methods to handle deadlocks

  1. Deadlock Ignorance(Ostrich method)
    Trade off between deadlock ignorance and performance happens in this method. We just ignore the deadlock and do not write any code to prevent or manage it, so that it increases the performance of the OS. This is because the code for deadlock detection, prevention or correction is quite complex. Programmers tend to ignore it because deadlocks happen very rarely and they do not want to compromise on the performance of the OS because of this extra functionality.

  2. Deadlock Prevention
    Prevent the 4 necessary conditions of deadlock formation from occurring, or atleast try to remove one of the condition, effectively preventing a deadlock. Prevent any four or all four.

  3. Deadlock Avoidance(Banker's Algorithm)
    Every time we allocate resources to a process, we check wether it is safe or unsafe to do it, and wether it will cause a deadlock. Banker's algorithm solves this problem.

  4. Deadlock Detection & Recovery
    We detect wether there is a deadlock, and if a deadlock is found, we try to recover the system from it.

Conclusion

You can read other articles written by me through these links.

Operating System Series
1. Introduction & Types of OS
2. Process States & Lifecycle
3. System Calls
4. User Mode vs Kernel Mode
5. CPU Process Scheduling
6. Process Synchronization
7. Deadlocks
8. Memory Management
9. Disk Management & Scheduling
10. File System in OS
11. Protection & Security

System Design Series
Introduction To Parallel Computing
Deep Dive Into Virtualization
Insights Into Distributed Computing

Cloud Computing Series
1. Cloud Service Models
2. Cloud Deployment Models
3. Cloud Security
4. Cloud Architecture
5. Cloud Storage
6. Networking In The Cloud
7. Cloud Cost Management
8. DevOps In Cloud & CI/CD
9. Serverless Computing
10. Container Orchestration
11. Cloud Migration
12. Cloud Monitoring & Management
13. Edge Computing In Cloud
14. Machine Learning In Cloud

Computer Networking Series
1. Computer Networking Fundamentals
2. OSI Model
3. TCP/IP Model : Application Layer
4. TCP/IP Model : Transport Layer
5. TCP/IP Model : Network Layer
6. TCP/IP Model : Data Link Layer

Version Control Series
1. Complete Guide to Git Commands
2. Create & Merge Pull Requests
3. Making Open Source Contributions

Linux
Complete Guide to Linux Commands

Thanks For Reading! ๐Ÿ’™
Garvit Singh

ย