There are four methods of handling deadlock:-

  1. The ostrich approach 
  2. Deadlock prevention
  3. Deadlock avoidance
  4. Deadlock detection and recovery

1.  The ostrich approach

Just ignore the deadlock problem altogether.

2.  Deadlock prevention

Deadlock hindrance may be a set of ways for guaranteeing that a minimum of one among the dead-end necessary conditions cannot hold.
OR
For situations to occur, every one of the four necessary conditions should hold. By ensuring that a minimum of one among these conditions cannot hold, one will forestall the prevalence of a dead end.
Deadlock is often prevented by making certain that a minimum of one amongst the four conditions fails to carry.
The four deadlock conditions are:-

To know the basic of deadlock condition click here

condition-of-deadlock
Condition of deadlock

  • Mutual excision condition

This condition is often removed by creating all the unsharable resources into sharable. But some resources like printer ar inherently non-shareable.
Therefore, these resources cannot be changed from non-shareable to sharable. So, mutual exclusion conditions cannot totally be removed.

  • Hold and wait condition

There are two ways to eliminate or remove the "hold and wait" condition:-
I)  A process should request and obtain all the requested resources before its execution starts.
Example:-
To take the print out of a file, the primary request and acquire the disk and printer

II) A method ought to unleash all its resources before it requests further resources.
Example:-
To take the output signal of a file, you initially request the disk, catch on to use it, and unleash it. Then you request the printer, catch on to use it, and unleash it. Then you request the printer, get it, use it, release it.

DISADVANTAGE OF HOLD AND WAIT CONDITION

:- Resource utilization may below.
:- Starvation may occur.

  • No-preemption condition

There are two ways to eliminate/remove the "No-preemption" condition:-
I) A method holding a precise resource and requesting for an additional resource should unleash them once more resource. If necessary, request them once more in conjunction with the extra resource.
II) A resource needed by one method and command by a second may be forcefully off from the second.

DISADVANTAGE OF NO-PREEMPTION

I) Preemption is feasible just for bound varieties of resources like hardware and main memory.
II) typically this technique preempts a lot of typically than necessary.

  • Circular and wait condition

3.  Deadlock avoidance

Deadlock may be avoided if sure info concerning processes is out there prior to resource allocation.
(a) Safe state
A safe state is one where
  • It is not a deadlock state.
  • There is some sequence by that all requests may be happy. 
  • To avoid deadlock, we try to make only those traditions that will take you from one safe state to another.

(b) Unsafe state
The system is said to be in an unsafe state if no safe sequence exists. A deadlock state is a form of an unsafe safe. Avoiding the system from getting into associate degree unsafe will avoid a dead end.

Deadlock-avoidance
 Deadlock  avoidance

4. Deadlock detection and recovery

Deadlock Recovery

A traditional package like Windows doesn’t alter impasse recovery as a result of its time and house overwhelming technique. time period operative systems use impasse recovery.

Recovery methodology


Killing {the method|the method}: killing all the processes concerned within the impasse. Killing method one by one. when killing every method check for impasse once more keep repetition the method until the system endures impasse.

Resource Preemption: Resources area unit preempted from the processes concerned within the impasse, preempted resources area unit allotted to different processes so there's a clear stage of ill the system from the impasse. during this case, the system goes into starvation