Process Deadlocks in Operating System (2024)

A deadlock happens in operating system when two or more processes need some resource to complete their execution that is held by the other process.

Process Deadlocks in Operating System (1)

In the above diagram, the process 1 has resource 1 and needs to acquire resource 2. Similarly process 2 has resource 2 and needs to acquire resource 1. Process 1 and process 2 are in deadlock as each of them needs the other’s resource to complete their execution but neither of them is willing to relinquish their resources.

Coffman Conditions

A deadlock occurs if the four Coffman conditions hold true. But these conditions are not mutually exclusive.

The Coffman conditions are given as follows −

  • Mutual Exclusion

    There should be a resource that can only be held by one process at a time. In the diagram below, there is a single instance of Resource 1 and it is held by Process 1 only.

    Process Deadlocks in Operating System (2)
  • Hold and Wait

    A process can hold multiple resources and still request more resources from other processes which are holding them. In the diagram given below, Process 2 holds Resource 2 and Resource 3 and is requesting the Resource 1 which is held by Process 1.

    Process Deadlocks in Operating System (3)
  • No Preemption

    A resource cannot be preempted from a process by force. A process can only release a resource voluntarily. In the diagram below, Process 2 cannot preempt Resource 1 from Process 1. It will only be released when Process 1 relinquishes it voluntarily after its execution is complete.

    Process Deadlocks in Operating System (4)
  • Circular Wait

    A process is waiting for the resource held by the second process, which is waiting for the resource held by the third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular chain. For example: Process 1 is allocated Resource2 and it is requesting Resource 1. Similarly, Process 2 is allocated Resource 1 and it is requesting Resource 2. This forms a circular wait loop.

    Process Deadlocks in Operating System (5)

Deadlock Detection

A deadlock can be detected by a resource scheduler as it keeps track of all the resources that are allocated to different processes. After a deadlock is detected, it can be resolved using the following methods −

  • All the processes that are involved in the deadlock are terminated. This is not a good approach as all the progress made by the processes is destroyed.
  • Resources can be preempted from some processes and given to others till the deadlock is resolved.

Deadlock Prevention

It is very important to prevent a deadlock before it can occur. So, the system checks each transaction before it is executed to make sure it does not lead to deadlock. If there is even a slight chance that a transaction may lead to deadlock in the future, it is never allowed to execute.

Deadlock Avoidance

It is better to avoid a deadlock rather than take measures after the deadlock has occurred. The wait for graph can be used for deadlock avoidance. This is however only useful for smaller databases as it can get quite complex in larger databases.

Updated on: 10-Sep-2023

35K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started

Process Deadlocks in Operating System (7)

Advertisem*nts

Process Deadlocks in Operating System (2024)

FAQs

Process Deadlocks in Operating System? ›

A deadlock in OS is a situation in which more than one process is blocked because it is holding a resource and also requires some resource that is acquired by some other process. The four necessary conditions for a deadlock situation are mutual exclusion, no preemption, hold and wait and circular set.

What is an example of a deadlock process? ›

For example, a computer has three USB drives and three processes. Each of the three processes able to holds one of the USB drives. So, when each process requests another drive, the three processes will have the deadlock situation as each process will be waiting for the USB drive to release, which is currently in use.

Which processes are deadlocked? ›

A set of processes is deadlocked when every process in the set is waiting for a resource that is currently allocated to another process in the set ( and which can only be released when that other waiting process makes progress. )

How many processes are involved in deadlock? ›

Deadlock occurs when two or more processes are unable to proceed because each process is waiting for a resource that is being held by another process. Deadlock is an infinite waiting situation where processes are stuck in a circular dependency and cannot progress.

What are the two types of deadlocks? ›

The paper then proposes two types of deadlocks based on these blocked relations, that is, block-cycle type deadlocks and waiting-block type deadlocks which are acyclic. It also presents an example of implementation to detect these types of deadlocks, and addresses future directions.

What is a deadlock process in operating system? ›

Deadlock in OS refers to a situation where more than one or two processes or threads are not able to proceed because each is waiting for the other to release a resource. In other words, it's a state where a group of processes become stuck in a way that they can't make any progress.

What are the 4 ways to solve deadlock? ›

4. Deadlock Prevention
  • 4.1. No Mutual Exclusion. It means more than one process can have access to a single resource at the same time. ...
  • 4.2. No Hold and Wait. ...
  • 4.3. Removal of No Preemption. ...
  • 4.4. Removal of Circular Wait.

How to avoid deadlock in OS? ›

Deadlock can be prevented by eliminating any of the four necessary conditions, which are mutual exclusion, hold and wait, no preemption, and circular wait. Mutual exclusion, hold and wait and no preemption cannot be violated practically. Circular wait can be feasibly eliminated by assigning a priority to each resource.

What are the 4 causes of deadlock in OS? ›

The four necessary conditions for a deadlock situation are mutual exclusion, no preemption, hold and wait and circular set. There are four methods of handling deadlocks - deadlock avoidance, deadlock prevention, deadline detection and recovery and deadlock ignorance.

What are the 4 requirements for deadlock? ›

A deadlock needs four conditions to occur: Mutual Exclusion (2 processes cannot use resource at the same time), Hold and Wait (process holds a resource and requests another), Non-Preemption of resources (the system doesn't take away resources from waiting processes - processes release resources voluntarily after they ...

How to recover from deadlock in OS? ›

If a deadlock occurs, the operating system needs to recover from it by breaking the cycle of waiting processes. There are two main strategies for doing this: process termination and resource preemption.

How do you detect deadlocks? ›

Deadlocks can be detected by looking for cycles in the graph. Detection by System Modeling: A mathematical model of the system is created, and deadlocks can be detected by finding a state in the model where no process can continue to make progress.

What are the three basic techniques to control deadlocks? ›

The three basic techniques to control deadlocks are:
  • Deadlock preventation . A transaction requesting a new lock is aborted when there is the possibility that a deadlock can occur. ...
  • Deadlock detection. The DBMS periodically tests the database for deadlocks. ...
  • Deadlock avoidance.

What is a real life example of a deadlock condition? ›

Another real-world example of deadlock is the use of a single track by multiple trains. Say multiple tracks converge onto one; there is a train on each individual track, leading to the one track. All trains are stopped, waiting for another to go, though none of them move.

What is an example of a deadlock transaction? ›

In a database, a deadlock is a situation in which two or more transactions are waiting for one another to give up locks. For example, Transaction A might hold a lock on some rows in the Accounts table and needs to update some rows in the Orders table to finish.

What is an example of the word deadlock? ›

Examples of deadlock in a Sentence

City councilors reached a deadlock over the law. His goal broke a 3–3 deadlock. These examples are programmatically compiled from various online sources to illustrate current usage of the word 'deadlock.

What is an example of a deadlock in business? ›

Shareholder deadlock is common: a company with 2 directors and shareholders, each owning 50%, cannot agree at board or shareholder level. No decisions can be made. In the legal sense, the company is “deadlocked”.

Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 5986

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.