Aim:
To implement Banker’s algorithm.
Algorithm:
- start
- read the number of processes and resources into m and n respectively.
- read the allocation matrix alloc[ ] [ ]
- read the number of each resource type.
- read the maximum claim table[ ] [ ]
- for each resource j,calculate avail[ j ] by the following steps:
set s=0
for each process i, s+=a[ i ] [ j ]
avail[ j ] = c[ i ] – s - for each process i,do the following
for each process j,do the following
x=max[ i ] [ j ] – a[ i ] [ j ]
if x<max[ j ]
if j=n-1 and i’th process is not already allocated
pr=1
goto 8
else
j=0
get out of the internal loop. - if no process has been allocated so far
print unsafe and exit
else
calculate new available matrix by following
for each resource j,do the following
avail[ j ]+=a[ pr ] [ i ]
for each process i,do the following
for each resource j,do the following
if i=m-1 and j=n-1
print “safe”
exit (0)
else
goto 6 - stop
Leave a comment