Featured Post

Different types of communication devices

Different types of communication devices  NIC & Bridge Network interface card  Network interface card is a communication d...

Monday, September 2, 2019

Methods of handling deadlock & Deadlock Preventation

Methods of handling deadlock 




  1. Deadlock Prevention
  2. Deadlock Avoidence
  3. Deadlock  Detection



Deadlock can be handled in different ways

  • We can use specific protocol to prevent avoid that last so that a system may never entered at last state. 
  • We can detect the deadlock and recover it. 
  • We can totally ignore the deadlock problem. 


Deadlock prevention 


We can prevent deadlock by ensuring that at least one of the four necessary conditions for deadlock cannot occur. If at least one condition is not satisfied a deadlock will not occur.

Mutual exclusion
Mutual exclusion condition must hold for non shareable resources. For example only one process can have access to a printer at a time otherwise output is disturbed. Some resources can be made Chef Rebel like a read only file. Several process can be granted read only access to a file without interfering with each other. However, deadlock enough is prevented by on the denying the mutual exclusion condition because some resources are intrinsically non shareable.

hold and wait

Deadlock can be prevented by denying the hold and wait precondition. This can be implemented in two different ways.
1. One approach is that a process request all the resources that it needs in one single request at process startup. The system will not grant any resource in the list until it came grant all the required resources.
2. Restrictive approach is to allow a process to request resources only when it is currently holding no resources. If a process needs a new resource, it must first release all the resources it has and then put the request. It may include a request for the allocation of a resource it just released.

Problems with this approach
If we allocate all resources at a time it may hold resources when it does not need them. It reduces resource utilization this is specially serious if a process does not know what resource it will actually need for a given execution until it has started working on the data. The process request all the resources it need.

A process that needs several popular resources might face starvation. Some processes may never execute in some other processes always has control up some required resources.

No Preemption

It means that we take away resources from processes when they are waiting for other resources. It could work in the following ways

1. As soon as process request for a resource that is not available all of its health resources are released. The process is now waiting for all of previously held resources + the resources that is requested. Suppose a process holds a tape drive and request a line printer. If line printer is not available, the tape drive is taken away and the process is put into a state of waiting for both thee tape drive  and line printer.

2. Trainer process request a resource that is available it gets it otherwise the system check those processes that are holding the requested resources and may be waiting for some more resources. In this case, the resource is taken away from the waiting process and allocated to the requesting process. If this cannot happen the process has to wait during the weights some other processes may get some of its sources.

Circular wait

we can prevent deadlock by making circular wait impossible. We can define in order by which processes get resources to prevent circular waste for example each resource type is assigned a number. The processes can only get resources in increasing order of those resource numbers. Tape drive has number 1 describe has number 5 in printer has number 12. A process wants to reach that is drive and print out the results it was first need to educate the describe than the princess it will be prevented from doing it in reverse order.

No comments:

Post a Comment