Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Deadlock Avoidance and Banker's Algorithm, Study notes of Operating Systems

The concept of deadlock avoidance, which is a method of dynamically escaping from deadlocks. It describes the Banker's algorithm, which is a deadlock avoidance algorithm used to prevent deadlocks in a system. The algorithm checks the state of the system before allocating resources to a process. The document also explains the concept of a safe state and provides data structures for the Banker's algorithm. The safety algorithm is also explained in detail. useful for students studying operating systems and computer science.

Typology: Study notes

2016/2017

Available from 03/10/2023

subhrajit-chakraborty
subhrajit-chakraborty 🇮🇳

5 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Deadlock avoidance
It is one of the methods of dynamically escaping from the dead locks. The word
dynamically means ‘Online’. In this scheme if a process request for resources the
avoidance algorithm checks before the allocation of resources about the state of system. If
the state is safe the system allocate the resources to the requesting process otherwise
(unsafe) do not allocate the resources. So taking care before the allocation is said to be
deadlock avoidance.
Safe state: No deadlock will happen, even we allocate the resources to requesting
processes.
Banker’s algorithm
It is deadlock avoidance algorithm, the name was chosen because the bank never
allocates more than the available cash.
Multiple instances.
Each process must a priori claim maximum use.
When a process requests a resource it may have to wait.
When a process gets all its resources it must return them in a finite amount of time.
Deadlock
Safe
Unsafe
pf3
pf4

Partial preview of the text

Download Deadlock Avoidance and Banker's Algorithm and more Study notes Operating Systems in PDF only on Docsity!

Deadlock avoidance

It is one of the methods of dynamically escaping from the dead locks. The word dynamically means ‘Online’. In this scheme if a process request for resources the avoidance algorithm checks before the allocation of resources about the state of system. If the state is safe the system allocate the resources to the requesting process otherwise (unsafe) do not allocate the resources. So taking care before the allocation is said to be deadlock avoidance.

Safe state : No deadlock will happen, even we allocate the resources to requesting

processes.

Banker’s algorithm

 It is deadlock avoidance algorithm, the name was chosen because the bank never allocates more than the available cash.  Multiple instances.  Each process must a priori claim maximum use.  When a process requests a resource it may have to wait.  When a process gets all its resources it must return them in a finite amount of time.

Deadlock

Safe

Unsafe

Data Structures for the Banker’s Algorithm

Let n = number of processes, and m = number of resources types.

Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available. Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj. Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj. Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task.

Need [i,j] = Max[i,j] – Allocation [i,j].

Safety Algorithm

  1. Let Work and Finish be vectors of length m and n , respectively. Initialize: Work = Available Finish [ i ] = false for i - 1,3, …, n.
  2. Find and i such that both: (a) Finish [ i ] = false (b) NeediWork If no such i exists, go to step 4.
  3. Work = Work + Allocationi

Finish [ i ] = true go to step 2.

  1. If Finish [ i ] == true for all i , then the system is in a safe state

Now we have to calculate the need matrix:

  • Now we know the need matrix and available matrix, so we can apply the banker’s algorithm on this example. Search the need matrix from P0 to P4 which is less than the available matrix, (1,2,2)<(3,3,2). Then allocate the requesting resource to P1. Now the process P may allocate (2,0,0+1,2,2)=(3,2,2).
  • After the completion of job P1, it releases the total resources, then available resource is (3,3,2+2,0,0)=(5,3,2).
  • Search the need matrix again, which is less than the available (0,1,1)<(5,3,2). So allocate resources to P3. after the completion of P3, it releases all its resources. Then the available =(available+allocation). It is (5,3,2+2,1,1)=7,4,3. continues this process until we find the safe state otherwise wait. The safe state sequence for this problem is <P1,P3,P4,P2,P0>

Need= Max-Allocation

R1 R2 R

P0 (7-0) (5-1) (3-0)

P1 (3-2) (2-0) (2-0)

P2 (9-3) (0-0) (2-2)

P3 (2-2) (2-1) (2-1)

P4 (4-0) (3-0) (3-2)