0% found this document useful (0 votes)
40 views

Deadlock in Operating System

The document discusses deadlock, its necessary conditions, and methods for handling it. It defines deadlock as when processes are waiting for resources held by other processes in the set, preventing any from progressing. Four conditions must be met for deadlock to occur: mutual exclusion, hold and wait, no preemption, and circular wait. It also discusses safe states, deadlock avoidance algorithms like resource allocation graphs and Banker's algorithm, and methods for deadlock recovery through preemption, rollback, or killing processes.

Uploaded by

Lata Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Deadlock in Operating System

The document discusses deadlock, its necessary conditions, and methods for handling it. It defines deadlock as when processes are waiting for resources held by other processes in the set, preventing any from progressing. Four conditions must be met for deadlock to occur: mutual exclusion, hold and wait, no preemption, and circular wait. It also discusses safe states, deadlock avoidance algorithms like resource allocation graphs and Banker's algorithm, and methods for deadlock recovery through preemption, rollback, or killing processes.

Uploaded by

Lata Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1. What is deadlock?

What are the four necessary conditions for deadlock to


occur?

The computer system uses may types of resource which are then used by various
processes to carry out their individual functions. But problem is that the amount of
resources available is limited and many processes need to use it. A set of process is
said to be in a deadlocked state when every process in the set is waiting for an event
that can be caused only by another process in the set. The event can be resource
acquisition, resource release etc. The resource can be physical (printers, memory
space) or logical (semaphores, files)

The necessary and sufficient conditions for deadlock to occur are:


• Mutual Exclusion
o A resource at a time can only be used by one process.
o If another process is requesting for the same resource, then it must be
delayed until that resource is released.
• Hold and Wait
o A process is holding a resource and waiting to acquire additional
resources that are currently being held by other processes.
• No Pre-emption:
o Resources cannot be pre-empted
o Resource can be released only by the process currently holding it based
on its voluntary decision after completing the task
• Circular wait
o A set of processes { P0,P1,….,Pn-1,Pn } such that the process P0 is waiting
for resource held by P1,P1 is waiting for P2 ,and Pn is waiting for P0 to
release its resources.
o Every process holds a resource needed by the next process.

2. Cycle is necessary condition for deadlock to occur but not a sufficient


condition. Justify.
By using resource allocation graph, it can be shown that, if the graph contains no
cycles, then no process in the system is deadlocked. If the graph contains a cycle.
Then a deadlock may exist.
If each resource type has exactly one instance, then a cycle implies that a
deadlock has occurred. If the cycle involves only a set of resource types, each of
which has only a single instance, then a deadlock has occurred. Each process
involved in the cycle is deadlocked. In this case, a cycle is both a necessary
condition for existence of deadlock.
If a resource type has several instances, then a cycle does not necessary imply
that a deadlock has occurred. In this case, a cycle in the graph is a necessary but
not a sufficient condition for the existence of deadlock.

3. What is safe state?


A state is said to be a safe state if the system may allocate the required resources
to each process up to the maximum required in a particular sequence, without
facing deadlock. In a safe state, deadlock cannot occur.
4. What is Deadlock avoidance algorithm?
Deadlock avoidance is a technique used to avoid deadlock. It requires
information about how different processes would request different resources. If
given several processes and resources, we can allocate the resources in some
order to avoid the deadlock.

There are two types of deadlock avoidance algorithms on the basis of their
resources:
Algorithm which is used for single instance of a resource type is Resource-
allocation graph. This algorithm uses the resource allocation graph by
introducing a new edge called claim edge. The claim edge is used to indicate that
a process may request a resource in future. It is represented by a dashed line.
When the process requests that resource, the dashed line is converted to an
assignment edge. i.e. a solid line. It indicates that the resource has been allocated
to the process. After the process releases this resource, the assignment edge is
again converted to claim edge. When a process requests a resource, it is
allocated only if converting the request edge to an assignment edge does not
form a cycle in the graph. If no cycle is formed, the system is in safe state and the
resource will be allocated. But if there is a cycle, the system will enter an unsafe
state and the process will wait for the resource.

Algorithm which is used for Multiple instances of a resource type is given as


Banker’s algorithm. It requires that each new process should declare the
maximum number of instances of each required resource type. When a process
requests certain resources, the system determines whether the allocation of
those resources will leave the system in safe state. If it will, the resources are
allocated. Otherwise, the process must wait until some other process releases the
resources.

The banker’s algorithm allows the following:

• Mutual exclusion
• Wait and hold
• No pre-emption
It prevents Circular wait
Let n be the number of processes and m be the number of the resource type.
Following data structures are required:

• Available: A vector of length m indicates the number of available resources of


each type.
• Max: An n x m matrix indicates the maximum requirements of each process.
• Allocated: The n x m matrix indicates the number of resources of each type
currently allocated to each process.
• Need: The n x m matrix indicates the remaining resource need of each
process.
5. What is Deadlock Recovery?

After the detection of deadlock, a method must require to recover that deadlock to run
the system again. The method is called as deadlock recovery.

Here are various ways of deadlock recovery:

Deadlock Recovery through Pre-emption

The ability to take a resource away from a process, have another process use it, and
then give it back without the process noticing. It is highly dependent on the nature of
the resource.

Deadlock recovery through pre-emption is too difficult or sometime impossible.

Deadlock Recovery through Rollback

Whenever a deadlock is detected, it is easy to see which resources are needed.

To do the recovery of deadlock, a process that owns a needed resource is rolled back to
a point in time before it acquired some other resource just by starting one of its earlier
checkpoints.

Deadlock Recovery through Killing Processes

This method of deadlock recovery through killing processes is the simplest way of
deadlock recovery.

Sometime it is best to kill a process that can be return from the beginning with no ill
effects.

You might also like