Deadlock Avoidance is used by Operating System to Avoid Deadlock in the System. The processes need to specify the maximum resources needed to the Operating System so that the Operating System can simulate the allocation of available resources to the requesting processes and check if it is possible to satisfy the need of all the processes requirements.
Deadlock Avoidance is a process used by the Operating System to avoid Deadlock. Let's first understand what is Deadlock in Operating System. Deadlock is a situation that occurs in Operating System when any Process enters a waiting state because another waiting process is holding the demanded resource.
But how can Operating System avoid Deadlock?
Operating System avoids Deadlock by knowing the maximum resources requirements of the processes initially, and also Operating System knows the free resources available at that time. Operating System tries to allocate the resources according to the process requirements and checks if the allocation can lead to a safe state or an unsafe state. If the resource allocation leads to an unsafe state, then Operating System does not proceed further with the allocation sequence.
State:
We use two words,
safe and unsafe states.
Safe State - In the above example, we saw that Operating System was able to satisfy the need of all three processes, P1, P2, and P3, with their resource requirements. So all the processes were able to complete their execution in a certain order like P3->P2->P1.
So, If Operating System is able to allocate or satisfy the maximum resource requirements of all the processes in any order then the system is said to be in Safe State.
So safe state does not lead to Deadlock.
Unsafe State - If Operating System is not able to prevent Processes from requesting resources which can also lead to Deadlock, then the System is said to be in an Unsafe State.
Unsafe State does not necessarialy cause deadlock it may or maynot causes deadlock.
Deadlock Avoidance Solution
Deadlock Avoidance can be solved by two different algorithms:
Resource allocation Graph
Banker's Algorithm
Resource Allocation Graph
Resource Allocation Graph (RAG) is used to represent the state of the System in the form of a Graph. The Graph contains all processes and resources which are allocated to them and also the requesting resources of every Process. Sometimes if the number of processes is less, We can easily identify a deadlock in the System just by observing the Graph, which can not be done easily by using tables that we use in Banker's algorithm.
Resource Allocation Graph has a process vertex represented by a circle and a resource vertex represented by a box. The instance of the resources is represented by a dot inside the box. The instance can be single or multiple instances of the resource.
Banker's Algorithm
Banker's algorithm does the same as we explained the Deadlock avoidance with the help of an example. The algorithm predetermines whether the System will be in a safe state or not by simulating the allocation of the resources to the processes according to the maximum available resources. It makes an "s-state" check before actually allocating the resources to the Processes.
When there are more number of Processes and many Resources, then Banker's Algorithm is useful.
Comments
Post a Comment