(Contains all about Deadlock and Cloud Services)
- By BeginnerCoder21
4 conditions of deadlock
Deadlock
● situation where a set of processes are blocked because each process is holding a
resource and waiting for another resource acquired by some other process.
● Mutual Exclusion
○ There must exist at least one resource in the system which can be used by
only one process at a time.
○ If there exists no such resource, then deadlock will never occur.
○ Printer is an example of a resource that can be used by only one process at a
time.
● Hold and Wait
○ must exist a process which holds some resource and waits for another
resource held by some other process.
● No preemption
○ Once the resource has been allocated to the process, it can not be
preempted.
○ resource can not be snatched forcefully from one process and given to the
other process.
○ process must release the resource voluntarily by itself.
● Circular wait
○ All the processes must wait for the resource in a cyclic manner where the last
process waits for the resource held by the first process.
In exam, explain this
,Deadlock Prevention
● Provides a set of methods to ensure that one of the four necessary conditions is
violated that are required for the occurrence of deadlock.
● This ensures that the system remains free from the deadlock.
● Eliminate Mutual Exclusion-
○ To violate this condition, all the system resources must be such that they can
be used in a shareable mode.
○ In a system, there are always some resources which are mutually exclusive by
nature.
● Solve Hold & Wait-
○ Approach 1 (eliminating wait)
■ process specifies the resources it requires in advance so that it does
not have to wait for allocation after execution starts. (take restaurant
eg)
■ But this approach lead to Low device utilisation
● Eg: If a process requires a printer at a later time & we allocated
printer before start of its execution, printer will remain blocked
till it has completed its execution.
■ Eg: Process1 declares in advance that it requires both Resource1 and
Resource2
○ Approach 2 (eliminating hold)
■ The process has to release all resources it is currently holding before
making a new request. (eg: plate of food)
■ approach is efficient and implementable.
■ This may lead to starvation
● Allow Preemption-
○ condition can by violated by forceful preemption. Forcefully preempt the
resources possessed by some other process only if- (eg: get the table free if )
● It is a high priority process or a system process. (VIP)
, ● The victim process is in the waiting state. (customer waiting for long
tym)
○ Consider a process holding some resources and requesting other resources
that can not be immediately allocated to it.
○ Then, by forcefully preempting the currently held resources, the condition
can be violated.
● Eliminate Circular Wait-
○ Circular Wait condition can be violated by not allowing the processes to wait
for resources in a cyclic manner (ask customer not to walk around)
○ We assign a priority to each resource. A process can only request resources in
increasing order of priority. (give priority to good table, a customer can order
food in increasing order)
○ approach is the most practical approach and implementable.
○ Eg: A media player will give a lesser priority to a printer while a document
processor might give it a higher priority. The priority of resources is different
according to the situation and use case.
Deadlock Avoidance
● strategy involves maintaining a set of data using which a decision is made whether to
entertain the new request or not. (maintain data for table booking)
● If entertaining the new request causes the system to move in an unsafe state, then it
is discarded.
● strategy requires that every process declares its maximum requirement of each
resource type in the beginning. (requires customer to tell no of people in advance)
● The main challenge with this approach is predicting the requirements of the
processes before execution.
● Banker’s Algorithm is an example of a deadlock avoidance strategy.
Deadlock Detection and Recovery-
● This strategy involves waiting until a deadlock occurs.
● After a deadlock occurs, the system state is recovered.
● The main challenge with this approach is detecting the deadlock.
Deadlock Ignorance-
● This strategy involves ignoring the concept of deadlock and assuming as if it does not
exist.
● This strategy helps to avoid the extra overhead of handling deadlock.
● Windows and Linux use this strategy and it is the most widely used method.
● It is also called as Ostrich approach.