Os May Be
Os May Be
resource types A, B and C. Following are the resources types: A has 10, B has 5 and the
resource type C has 7 instances.
P1 0 1 0 7 5 3
P2 2 0 0 3 2 2
P3 3 0 2 9 0 2
P4 2 1 1 2 2 2
P5 0 0 2 4 3 3
Process Need
A B C
P1 7 4 3
P2 1 2 2
P3 6 0 0
P4 0 1 1
P5 4 3 1
Now we check if each type of resource request is available for each process.
5, 3, 2 + 2, 1, 1 => 7, 4, 3
7, 4, 3 + 0, 0, 2 => 7, 4, 5
Now, we again examine each type of resource request for processes P1 and P3.
7, 4, 5 + 0, 1, 0 => 7, 5, 5
Hence, we execute the banker's algorithm to find the safe state and the safe
sequence like P2, P4, P5, P1 and P3.
Ans. 3: For granting the Request (1, 0, 2), first we have to check that Request <=
Available, that is (1, 0, 2) <= (3, 3, 2), since the condition is true. So the process P1 gets
the request immediately.
Deadlock Detection and Recovery
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.
We can snatch one of the resources from the owner of the resource (process) and give it
to the other process with the expectation that it will complete the execution and will
release this resource sooner. Well, choosing a resource which will be snatched is going
to be a bit difficult.
System passes through various states to get into the deadlock state. The operating
system canrollback the system to the previous safe state. For this purpose, OS needs to
implement check pointing at every state.
The moment, we get into deadlock, we will rollback all the allocations to get into the
previous safe state.
For Process
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.
This is not a suggestible approach but can be implemented if the problem becomes very
serious. Killing all process will lead to inefficiency in the system because all the
processes will execute again from starting.