Deadlock Handling Methods

Deadlock Handling Methods

A protocol can use to prevent or avoid deadlocks, making sure that system will never enter in a deadlock state. There are two deadlock handling methods:

  • Deadlock prevention
  • Deadlock avoidance

Let the system to enter a deadlock state detect it, and recover. Overlook the problem totally and invented that deadlocks never arise in the system.

Deadlock Prevention

Confine the ways request can be made:
Mutual Exclusion – not essential for sharable resources e.g., read-only files; must have for non-sharable resources.
Hold and Wait – must guarantee that every time a process requests a resource, it does not grip any other resources.
Require process to request and be allotted all its resources before it commences the execution, or let the process to request resources only when the process has nothing allocated to it. Low resource utilization and starvation is possible.

Example for Hold and wait
All the required resources can be assigned to a process before execution or permit process to request resources only when the process has nothing allocated to it.

■ To demonstrate the difference b/w these two protocols, suppose a process that copies data from a DVD drive to a file on disk, sorts the file, and then prints the results to a printer. Incase if all resources must be requested at the start of the process, then the process must primarily request the DVD drive then disk file and printer. It would hold the printer for its whole execution, although it requires the printer only at the end.

The second method permits the process to request primarily only disk file and the DVD drive. It copies from the DVD drive to the disk and then reliefs both the disk file and the DVD drive. The process must then again request the printer and the disk file. After copying the disk file to the printer, it releases these two resources and ends.

■ First of all, resource utilization may be less, then resources can be allocated but idle for a long period, in above given example for instance, disk file and DVD drive are released, and then again request printer and the disk file and only if it is assured that our data will stay on the disk file.
■ If it is not certain that they will, then should request all resources at the start for both protocols.
■ Second of all, there is more chances of starvation. A process that wants numerous popular resources may have to wait for an indefinite period, because at-least one of the resources that it requires is always assigned to some other process.

Deadlock Avoidance Methods

As discussed in previous lecture that draw back of prevention method for deadlocks are less device utilization and decrease system throughput. A modified method for avoiding deadlocks is to involve additional information about how resources are to be requested.

■ Let’s take an example, in a system with one printer and one tape drive, the system might need to know that process P will request first the printer and then the tape drive before releasing these both resources, while process Q will request first the tape drive  and then the printer.

Needs that the system has few additional a priori information accessible
■ Easiest and most suitable model requires that each process announce the maximum number of resources of every type that it might require by the way of a priori information.
■ The deadlock-avoidance algorithm dynamically inspects the resource allocation state to make sure that there can never be a circular-wait condition
■ Resource allocation state is well-defined by the available and number of allocated resources with the max. demands of the processes

Safe State

A state is called its safe state if the system can allocate resources to every process up to its maximum in some order and still avoid a deadlock.
■ Once a process requests an available resource then system need to decide if immediate allocation leaves the system in its safe state.

A system is in safe state and if there occurs a sequence <P1, P2, …, Pn> of all the processes
in the systems such that for every Pi, the resources that Pi can still request may be satisfied by available resources plus resources held by all the Pj, with j < I.


■ That is: If Pi resource requirements are not immediately available, then Pi can wait till then all Pj have completed. When Pj is finished, Pi can get required resources, execute, return allocated resources and terminate. When Pi terminates, Pi +1 can attain its required resources and so on.

Basic Facts

If a system is in its safe state, then no deadlocks occurs. If a system is in its unsafe state then
there exist probability of deadlock. Avoidance make sure that a system will never enter an unsafe state.deadlock handling

Read more Deadlock


We are a team of writers, researchers, and editors who are passionate about helping others live their best lives. We believe that life is a beautiful gift. We try to live our lives to the fullest and enjoy every moment. We are always learning and growing, and we cherish the relationships we have with our family and friends.

Leave a Reply