In a multiprogramming environment, several process may compete for a finite number of resources. A process request resources, and if the resources are not available by the time, the process enters in a wait state. The process stated as wait can not change their state if the resources have requested held by other process in wait state. The situation called as Deadlock in operation system environment. Lets see an example, there are three processs, each process holding one of three tape drives. If each process now request another tape drive at the same time, the deadlock may occured.
A deadlock situation can arise if and only if the following four conditation occur simultaneously in a system. the situations are:
1) Mutual Exclusion
Only one process can use a resource at the same time. If another process request same resource, the process must be delayed until the resource has been released.
2) Hold and Wait
There must be one process that is having one resource and waiting for another resource that is being currently held by another process.
3) No Preemption
The situation in which any process can not pre-empt(killed) and can not be shared.
4) Circular wait condition
There must be a circular chain of two or more process. each process is waiting for a resource held by next member of the chain.
To deal with deadlock situation two method are used. One is called Deadlock Prevention and second is called Deadlock avoidence. Deadlock will come in picture when all four condition satisfies simultaneously. If any one condition will not exist,? deadlock will not occur. Let discuss these situation here in which we can avoid deadlock.
- The mutual exclusion condition must hold for non sharable type of resources. for example: a printer can not be share simultaneously by several process. sharable resources does not require mutually exclusive access, and thus can not be involved in deadlock.
- The hold and wait condition never occur in the system if a process can not request resource other then one. The mail disadvantage of this method is that resource utilization may be very slow, since many of the resources may be allocated but unused for a long period of time.
- If a process request some resources, we must check first if the resources are available. if so, we allocate them. If resources are not available, we check whether they are allocated to some other process or waiting for additional resources. If so, we preempt the desired resources from the waiting process and allocate them to the requesting process.
- Each process can only request resources in an increasing order of enumeration(priority). A process can initially request any number of instance of resource type, say Ri. After that, the process can request instance of resource type Rj if and only if F(Rj) > F(Ri). If several instance of the same resource type are needed , a single request for all of these all resource must be issued.