Recents in Beach

Banker’s Algorithm in Operating System

 Previous                                                          Next⏩



      
Banker's algorithm is a deadlock avoidance algorithm. It is named so because this algorithm is used in banking systems to determine whether a loan can be granted or not.
Consider there are n account holders in a bank and the sum of the money in all of their accounts is S. Everytime a loan has to be granted by the bank, it subtracts the loan amount from the total money the bank has. Then it checks if that difference is greater than S. It is done because, only then, the bank would have enough money even if all the n account holders draw all their money at once.
Banker's algorithm works in a similar way in computers.
Whenever a new process is created, it must specify the maximum instances of each resource type that it needs, exactly.


Let,
· n = number of processes
· m = number of resources types
§ Available: Vector of length m. If Available[j] = k, there are k instances of resource type Rjavailable.
§ Max: n x m matrix. If Max [i,j] = k, then process Pimay 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 Rjto complete its task.
Need [i,j] = Max[i,j] – Allocation [i,j].



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

3. Work = Work + Allocationi Finish[i] = true
go to step 2.

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


Example:
Considering a system with five processes P0 through P4 and three resources of type A, B, C. Resource type A has 10 instances, B has 5 instances and type C has 7 instances. Suppose at time t0 following snapshot of the system has been taken:

Question1. What will be the content of the Need matrix?
Need [i, j] = Max [i, j] – Allocation [i, j]
So, the content of Need Matrix is:
Question2.  Is the system in a safe state? If Yes, then what is the safe sequence?
Applying the Safety algorithm on the given system,
Question3. What will happen if process Prequests one additional instance of resource type A and two instances of resource type C?



       Previous                                               Next⏩


  1. What is an Operating System ?
  2. Discuss the structure off OS ?
  3. Explain type of OS?
  4. Explain Function of OS?
  5. Explain OS Services ?
  6. What do mean by system call ?List different type ofsystem call available ?

  1. what is process ? and Characteristics ?
  2. What is different process state? explain the same in details?
  3. write short note on user level and kernal level threads?
  4. explain what is thread and its type ?
  5. explain scheduler ? (short term,medium term,and long term)
  6. state and explain scheduling criteria ?
  7. Explain scheduling algorithm ? [ FCFS,SJF,PRIORITY,ROUND ROBINE.]    

  1. What is process synchronization ? explain critical section problem and race condition ?
  2. what is Race Condition ?
  3. what is critical section problem?
  4. explain classical problem of synchronization?
  5. explain bounded - buffer problem?
  6. explain reader - writer problem ?
  7. explain Dining Philosophers Problem ?
  8. explain semaphores ? its type ?

  1.  What is deadlock ?
  2. What are the 4 condition to produce deadlock ?
  3. explain methods of handling deadlock ?
  4. explain in detail deadlock prevention ?
  5. write short note on deadlock avoidance ?
  6. explain deadlock detection ? 
  7. explain Banker algorithm with example ? 

Post a Comment

0 Comments