Banker's Algorithm: Import As Import As
Banker's Algorithm: Import As Import As
Banker's Algorithm
In [8]: Allocated = {
'p1':[1, 0, 2, 1, 1],
'p2':[2, 0, 1, 1, 0],
'p3':[1, 1, 0, 1, 1],
'p4':[1, 1, 1, 1, 0]
}
Max = {
'p1':[1, 1, 2, 1, 3],
'p2':[2, 2, 2, 1, 0],
'p3':[2, 1, 3, 1, 1],
'p4':[1, 1, 2, 2, 0]
}
Allocated = pd.DataFrame(Allocated).transpose()
Max = pd.DataFrame(Max).transpose()
aval = [0,0,2,1,1]
FUTURE NEED
p1 0 1 0 0 2
p2 0 2 1 0 0
p3 1 0 3 0 0
p4 0 0 1 1 0
http://localhost:8888/nbconvert/html/Jupyter%20Notebooks/OS-practicals/Bankers_Algorithm.ipynb?download=false Page 1 of 2
Bankers_Algorithm 17/04/20, 6:26 PM
In [9]: SafeSeq = []
flag = len(futureNeed)
while(flag>0):
for x in range(len(futureNeed)):
label = futureNeed.index.values[x]
req = list(futureNeed.iloc[x])
freed = list(Allocated.iloc[x])
flag = flag-1
if len(SafeSeq)<len(Allocated):
print("\033[31mNO SAFE-SEQ FOUND!!\033[0m")
print(SafeSeq)
print(len(Allocated))
print(len(SafeSeq))
print
else:
print("Safe Sequence = ",SafeSeq)
http://localhost:8888/nbconvert/html/Jupyter%20Notebooks/OS-practicals/Bankers_Algorithm.ipynb?download=false Page 2 of 2