Banker’s Algorithm

24 06 2008

Aim:

To implement Banker’s algorithm.


Algorithm:

  1. start
  2. read the number of processes and resources into m and n respectively.
  3. read the allocation matrix alloc[ ] [ ]
  4. read the number of each resource type.
  5. read the maximum claim table[ ] [ ]
  6. 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
  7. 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.
  8. 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
  9. stop

Actions

Information

Leave a comment




Design a site like this with WordPress.com
Get started