0% found this document useful (0 votes)
48 views7 pages

Os May Be

The document summarizes the banker's algorithm approach for deadlock detection and recovery. It describes creating a need matrix from the maximum and allocated resources for each process. It then applies the banker's algorithm by checking if the available resources can fulfill each process' needs in a safe sequence. For deadlock recovery, it discusses preempting resources from processes, rolling back to a safe state, killing processes, and killing all processes as potential options.

Uploaded by

Yawkal Addis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views7 pages

Os May Be

The document summarizes the banker's algorithm approach for deadlock detection and recovery. It describes creating a need matrix from the maximum and allocated resources for each process. It then applies the banker's algorithm by checking if the available resources can fulfill each process' needs in a safe sequence. For deadlock recovery, it discusses preempting resources from processes, rolling back to a safe state, killing processes, and killing all processes as potential options.

Uploaded by

Yawkal Addis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Example: Consider a system that contains five processes P1, P2, P3, P4, P5 and the three

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.

Process Allocation Max


A B C A B C

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

Answer the following questions using the banker's algorithm:

1. What is the reference of the need matrix?


2. Determine if the system is safe or not.
3. What will happen if the resource request (1, 0, 0) for process P1 can the system
accept this request immediately?

Ans. 2: Context of the need matrix is as follows:

Need [i] = Max [i] - Allocation [i]


Need for P1: (7, 5, 3) - (0, 1, 0) = 7, 4, 3
Need for P2: (3, 2, 2) - (2, 0, 0) = 1, 2, 2
Need for P3: (9, 0, 2) - (3, 0, 2) = 6, 0, 0
Need for P4: (2, 2, 2) - (2, 1, 1) = 0, 1, 1
Need for P5: (4, 3, 3) - (0, 0, 2) = 4, 3, 1

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

Hence, we created the context of need matrix.

Ans. 2: Apply the Banker's Algorithm:

Available Resources of A, B and C are 3, 3, and 2.

Now we check if each type of resource request is available for each process.

Step 1: For Process P1:

Need <= Available

7, 4, 3 <= 3, 3, 2 condition is false.

So, we examine another process, P2.

Step 2: For Process P2:

Need <= Available

1, 2, 2 <= 3, 3, 2 condition true

New available = available + Allocation

(3, 3, 2) + (2, 0, 0) => 5, 3, 2

Similarly, we examine another process P3.

Step 3: For Process P3:

P3 Need <= Available

6, 0, 0 < = 5, 3, 2 condition is false.

Similarly, we examine another process, P4.


Step 4: For Process P4:

P4 Need <= Available

0, 1, 1 <= 5, 3, 2 condition is true

New Available resource = Available + Allocation

5, 3, 2 + 2, 1, 1 => 7, 4, 3

Similarly, we examine another process P5.

Step 5: For Process P5:

P5 Need <= Available

4, 3, 1 <= 7, 4, 3 condition is true

New available resource = Available + Allocation

7, 4, 3 + 0, 0, 2 => 7, 4, 5

Now, we again examine each type of resource request for processes P1 and P3.

Step 6: For Process P1:

P1 Need <= Available

7, 4, 3 <= 7, 4, 5 condition is true

New Available Resource = Available + Allocation

7, 4, 5 + 0, 1, 0 => 7, 5, 5

So, we examine another process P2.

Step 7: For Process P3:

P3 Need <= Available

6, 0, 0 <= 7, 5, 5 condition is true

New Available Resource = Available + Allocation


7, 5, 5 + 3, 0, 2 => 10, 5, 7

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.

In order to recover the system from deadlocks, either OS considers resources or


processes.
For Resource

Preempt the resource

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.

Rollback to a safe state

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.

Kill all process

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.

You might also like