Dead Lock

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DeadLock

● In a multiprogramming environment, several processes required finite number of resources


to complete their task.

● A process requests resources if the resources are not available at that time, the process
enters a waiting state.

●Sometimes, a waiting process is never end, because the resources it has requested are held
by other waiting processes. This situation is called a deadlock.

System Model-
●A system consists of a finite number of resources to be distributed among a number of
competing processes.

●Resources can be divided into different groups, with each group having multiple identical items.

●If a process asks for a resource, giving it if it is available one of that type will meet the request.

●A process must request a resource before using it and must release the resource after using it.

●A process can ask for as many resources as it needs to do its job. But , it can't ask for more than the
available resources in our system. For example, it can't ask for three printers if there are only two
printers in the system.

How Process utilizes the resource-


●Request. The process requests the resource. If the request cannot be granted immediately
(for example, if the resource is being used by another process), then the requesting process
must wait until it can acquire the resource.

●Use. The process can operate on the resource (for example, if the resource is a printer, the
process can print on the printer).

●Release. The process releases the resources.

Deadlock Characterization: Necessary Conditions


(refers to the specific conditions that must be
present for a deadlock to occur in a system)-
●Mutual Exclusion-Mutual exclusion means that at least one resource is being used by only one
process at a time, and no other process can use it until it is released.
●Hold and Wait-Hold and wait means that a process is using at least one resource and is also waiting
to get more resources.

●Non-Primitive-No pre-emption means that resources cannot be taken away from a process that is
already using them.

●Circular Wait-Circular wait means that a group of processes are waiting for each other in a loop. For
example, Process A is waiting for a resource held by Process B, Process B is waiting for a resource
held by Process C, and Process C is waiting for a resource held by Process A.

Deadlock Detection (by Resources Allocation


Graph(RAG))-
● Resources are single instances and there exist a cycle in resources allocation graph there their must
Deadlock occur.

● If the resources are not single instances and a cycle is existed in resources allocation graph then
there may or may not Deadlock occur.

Methods for Handling Deadlocks-


● We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never
enter a deadlocked state.

● We can allow the system to enter a deadlocked state, detect it, and recover.

● We can ignore the problem and pretend (ढोंग करना) that deadlocks never occur in the system

Deadlock Prevention-
Deadlock prevention involves designing the system and its processes in a way that avoids
the conditions necessary for deadlock. Here are some common techniques-

● Mutual Exclusion: Ensure that resources cannot be simultaneously accessed by multiple


processes. By using this way we can prevent from deadlock.

● Hold and Wait- means when a process needs resources, it has to ask for it and get all the
resources it needs at once, instead of asking for them one by one. This way, the process won't hold
onto one resource and wait for another, which could cause a deadlock.

● . No Pre-emption- If a process is holding some resources and requests another resource that
cannot be immediately allocated to it (that is, the process must wait), then all resources the
process is currently holding are pre-empted. In other words, these resources are implicitly
released.
●Resource Ordering- means setting a rule for the order in which processes can ask for resources.
By doing this, we ensure that processes always ask for resources in the same order, which stops them
from getting stuck in a loop where each process is waiting for a resource held by the next one.

1-Bankers Algorithms
2-Safe and unsafe state

You might also like