How to Recover from Deadlock

Computing

Harsh Gupta - Tech Writer
Deadlock will occur in the system when processes wait to acquire resource to get executed. Deadlock mainly occurs due to following reasons:

· When two or more processes want to share a non-sharable resource.

· When a process acquired one resource and wants to acquire another resource to get completed. But, that needed resource is acquired by another process.

· Preempting a resource simply means that one process having higher priority will violently release and acquire the resources which are already possessed by another process.

· Another condition for deadlock is circular wait. Let the processes are within a sequence {p0, p (1), p (2)........p (n)} now p0 is waiting for p1 for resource and p1 is dependant on p2 for resource and.......... P (n) is waiting for p0.

These are the conditions, if one of them will occur in the system than we can say that system is under deadlock. Now I am discussing here that how to recover from deadlock:

Process termination:

It is a method in which all the processes which are grouped into the deadlock cycle are aborted. This can be done by two methods.

First method is to abort all the processes which are in the deadlock cycle. This will be at great expense because many of these processes are about to finish. And it will causes recomputation of these processes from the scratch.

The second method is that in which we abort only a single process from the deadlock cycle. And again check for the deadlock. If any deadlock cycle still exists then we again abort another process and check for the deadlock condition again. This process will continue until we recover from deadlock. But this process will also causes abortion of process which is about to complete. And we have to again execute that process from starting.

So we have to set a termination condition for the processes:

· About the priority of process

· How long it will take to complete its task

· How many and what type of resources has used by the process

· How many more processes are needed

Resource preemption:

To eliminate the deadlock condition another approach is preemption. We preempt some resources from processes and give these resources to other processes until we recover from the deadlock condition. For this we have to deal with following three conditions:

· First aspect to keep in mind is to select a victim. The victim is selected in such a manner that the cost factor is reduced to its minimum value. Cost factor will refer to the time it will still take and the resources it is holding.

· As we abort a process and then we have to start the code from the starting. It is missing some needed resources. Now rollback the process and restart it from the starting i.e. determine its safe state. But it is very difficult to find a safe state. It is an efficient method to recover from deadlock but the only problem is to keep information about the running state of all the processes.

· Sometimes a process is selected again and again as victim. It may also happen that this process will wait for a long time. It will cause the problem of starvation. Starvation means that a process is selected again and again as a victim i.e. another processes will preempt that process for resources. This problem can be handled through "aging". It will increase the cost factor of that process which will get preempt again and again. We will ensure that a same process can't be preempted again and again.

So, by following any of the above two methods we can easily recover form the deadlock condition.

Published by Harsh Gupta - Tech Writer

I am a part time freelancer and writing is my hobby Some of my websites: http://www.GenericArticles.com http://www.JailBreakingiPhone.com  View profile

  • It is a method in which all the processes which are grouped into the deadlock cycle are aborted.
  • Second method is that in which we abort only a single process from the deadlock cycle.
  • To eliminate the deadlock condition another approach is preemption.
First method is to abort all the processes which are in the deadlock cycle. This will be at great expense because many of these processes are about to finish. And it will causes recomputation of these processes from the scratch.

To comment, please sign in to your Yahoo! account, or sign up for a new account.