OS Unit - 5
OS Unit - 5
Principles of Deadlock:
In this scenario, a cycle is being formed among the three processes. None
of the process is progressing and they are all waiting. The computer
becomes unresponsive since all the processes got blocked.
Difference between Starvation and Deadlock:
Starvation:
Starvation is the problem that occurs when high priority processes keep
executing and low priority processes get blocked for indefinite time. In
heavily loaded computer system, a steady stream of higher-priority
processes can prevent a low-priority process from ever getting the
CPU. In starvation resources are continuously utilized by high priority
processes. Problem of starvation can be resolved using Aging. In Aging
priority of long waiting processes is gradually increased.
Deadlock Prevention:
1. Mutual Exclusion
2. Hold and Wait
3. No preemption
4. Circular wait
Mutual Exclusion:
It is not possible to dis-satisfy the mutual exclusion because some resources,
such as the tape drive and printer, are inherently non-shareable.
Allocate all required resources to the process before the start of its
execution, this way hold and wait condition is eliminated but it will lead to
low device utilization. for example, if a process requires printer at a later
time and we have allocated printer before the start of its execution printer
will remain blocked till it has completed its execution.
The process will make a new request for resources after releasing the
current set of resources. This solution may lead to starvation.
Eliminate No Preemption:
Preempt resources from the process when resources required by other high
priority processes.
Deadlock Avoidance:
In this method, the request for any resource will be granted only if the
resulting state of the system doesn't cause any deadlock in the system. This
method checks every step performed by the operating system. Any process
continues its execution until the system is in a safe state. Once the system
enters into an unsafe state, the operating system has to take a step back.
According to the simplest and useful approach, any process should declare the
maximum number of resources of each type it will need. The algorithms of
deadlock avoidance mainly examine the resource allocations so that there can
never be an occurrence of circular wait conditions.
Deadlock avoidance can mainly be done with the help of Banker's Algorithm.
A state is safe if the system can allocate resources to each process( up to its
maximum requirement) in some order and still avoid a deadlock. Formally, a
system is in a safe state only, if there exists a safe sequence. So a safe state is
not a deadlocked state and conversely a deadlocked state is an unsafe state.
In this approach, The OS doesn't apply any mechanism to avoid or prevent the
deadlocks. Therefore the system considers that the deadlock will definitely
occur. In order to get rid of deadlocks, The OS periodically checks the system for
any deadlock. In case, it finds any of the deadlock then the OS will recover the
system using some recovery techniques.
The main task of the OS is detecting the deadlocks. The OS can detect the
deadlocks with the help of Resource allocation graph.
In single instanced resource types, if a cycle is being formed in the system then
there will definitely be a deadlock. On the other hand, in multiple instanced
resource type graph, detecting a cycle is not just enough. We have to apply the
safety algorithm on the system by converting the resource allocation graph
into the allocation matrix and request matrix.
Deadlock Recovery:
For Resource
Kill a process:
Killing a process can solve our problem but the bigger concern is to
decide which process to kill. Generally, Operating system kills a process
which has done least amount of work until now.