Edit

Question :- Define deadlock . Explain the condition under which deadlock occur ?  ( Nov – Dec 18 )   ( 6 m)

Question:- Write necessary conditions for deadlock. ( May- June 18 )

Ans :- Following four conditions are necessary for deadlock :-

a) Mutual Exclusion :- Every resource is either free or assigned to exact one process.

b) Hold and wait :- A process may hold allocated resources while waiting for the allocation of other resources.

c) No pre-emption :-  Resources obtained by one process, can not be removed from process until the process has finished using the resource.

d) Circular Wait :- There must exists a closed chain of processes, each of which is waiting for a resource held by the next member of the chain.

All four of these conditions must be present for a resource deadlock to occur. If one of them is absent, no resource deadlock is possible. To prevent a deadlock, the OS must eliminate one of the four conditions. These four conditions can be modeled using a directed graph. The graph have two kinds of nodes :-

1)  Process, shown as circles

2) Resources, shown as squares.

An are from a resource node ( square ) to a process node ( circle ) means that the resources is currently being held by the process . An are from a process node ( circle ) to a resource node ( square ) means that the process is making a request for the resource.

Edit

Question     Explain deadlock prevention methods.                                                                  4 Marks

Ans:-     Conditions for preventing deadlock :-

1. Attacking the mutual exclusion condition =

In this method, no resource is assigned to a process. If this is the situation then we will never have deadlock. The basic idea is to avoid assigning a resources to a process.

1. Attacking the hold and wait  condition = We can eliminate deadlock, if a process holding a resource is never allowed to wait for more resources. In this method a process requesting a resource should first release all the resources held by process.
2. Attacking the no preemption condition =In this method, a resource can be forcibly taken away from the process if a process holds a resource R1 and needs another resource R2. If R2 is not available then resource R1 can be forcibly taken away from the process.
3. Attacking the circular wait condition = There are two ways of avoiding circular wait condition:
If a process is entitled for maximum of one resources at a time then the circular wait condition will never arise
A number is assigned to resources and a process is allowed to make requests for resources in numerical order.

References

Edit
• WikiNote Foundation