Write Steps of banker’s algorithm to avoid deadlock | Operating System Question & Answer

Steps of Banker’s Algorithm:  
This algorithm calculates resources allocated, required and available before allocating resources to any process to avoid deadlock. It contains two matrices on a dynamic basis. Matrix A contains resources allocated to different processes at a given time. Matrix B maintains the resources which are still required by different processes at the same time.  

Step 1: When a process requests for a resource, the OS allocates it on a trial basis. 
Step 2: After trial allocation, the OS updates all the matrices and vectors. This updating can be done by the OS in a separate work area in the memory. 
Step 3: It compares F vector with each row of matrix B on a vector to vector basis. 
Step 4: If F is smaller than each of the row in Matrix B i.e. even if all free resources are allocated to any process in Matrix B and not a single process can complete its task then OS concludes that the system is in unstable state. 
Step 5: If F is greater than any row for a process in Matrix B the OS allocates all required resources for that process on a trial basis. It assumes that after completion of process, it will release all the recourses allocated to it. These resources can be added to the free vector. 
Step 6: After execution of a process, it removes the row indicating executed process from both matrices. 
Step 7: This algorithm will repeat the procedure step 3 for each process from the matrices and finds that all processes can complete execution without entering unsafe state. For each request for any resource by a process OS goes through all these trials of imaginary allocation and updation. After this if the system remains in the safe state, and then changes can be made in actual matrices. 

Post a Comment

0 Comments