Free Essay

Bankers Alogoirthm

In:

Submitted By ranjith23
Words 406
Pages 2
CSEN5322 – Operating Systems
Homework-5
Student Name | Student ID | Section | Date | | | | |

Bankers Algorithm

The Banker's algorithm is a resource allocation and deadlock avoidance algorithm. Using C++ programming language, implement the Banker's algorithm for deadlock avoidance.
5 <= # of process, P0 ~ P4
4 <= # of resource, A ~ D
0 0 1 2 <= Allocation
1 0 0 0
1 3 5 4
0 6 3 2
0 0 1 4
0 0 1 2 <= Max
1 7 5 0
2 3 5 6
0 6 5 2
0 6 5 6
1 5 2 0 <= Available

5 <= # of process, P0 ~ P4
4 <= # of resource, A ~ D
0 0 1 2 <= Allocation
1 0 0 0
1 3 5 4
0 6 3 2
0 0 1 4
0 0 1 2 <= Max
1 7 5 0
2 3 5 6
0 6 5 2
0 6 5 6
1 5 2 0 <= Available

Input a txt file that includes the number of processes, resources, and the matrixes for allocations, max, and available.
Output Safe or Unsafe 1) Read the # of processes and the # of resources 2) Read allocation, max and available for each process and each resource 3) Print whether this system is safe or not to the output file.

Data Structures for the Banker’s Algorithm
Input.txt
Input.txt
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 = 0, 1, …, n- 1
2. Find an 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

Similar Documents

Free Essay

White Chicks Cant Dance

...President Hoover, Mr. Chief Justice, my friends: This is a day of national consecration. And I am certain that on this day my fellow Americans expect that on my induction into the Presidency, I will address them with a candor and a decision which the present situation of our people impels. This is preeminently the time to speak the truth, the whole truth, frankly and boldly. Nor need we shrink from honestly facing conditions in our country today. This great Nation will endure, as it has endured, will revive and will prosper. So, first of all, let me assert my firm belief that the only thing we have to fear is fear itself -- nameless, unreasoning, unjustified terror which paralyzes needed efforts to convert retreat into advance. In every dark hour of our national life, a leadership of frankness and of vigor has met with that understanding and support of the people themselves which is essential to victory. And I am convinced that you will again give that support to leadership in these critical days. In such a spirit on my part and on yours we face our common difficulties. They concern, thank God, only material things. Values have shrunk to fantastic levels; taxes have risen; our ability to pay has fallen; government of all kinds is faced by serious curtailment of income; the means of exchange are frozen in the currents of trade; the withered leaves of industrial enterprise lie on every side; farmers find no markets for their produce; and the savings of many years in...

Words: 1182 - Pages: 5