<

Lecture #8

Administrivia

Previously on CSS503A...

TODO: diagram

TODO: diagram

Banker's Algorithm

Prerequisites

M = # resource classes
N = # processes

Available[M] = # resources available for each class (0..M-1)
Max[N,M] = maximum demand for each resource, for each process
Allocation[N,M] = current allocation of each resource, for each prosess
Need[N,M] = Max - Allocation
   # each row is a vector with one element for each resource class

define X < Y  iff for all i in [0..M-1], X[i] < Y[i]

Safety algorithm

# Safety algorithm (lemma? subroutine?)
Work[M]
Finish[N]

Work = Available # currently available resources
Finish = False[N]
loop:
  find process i such that its maximum request could be satisfied (i.e. !Finish[i] & Need[i] < Work)
  if no such i:
    system is safe iff Finish == True[N]
    return
  # assume process i gets it's max request and is allowed to run to completion
  # then it's currently-held resources become available
  Work += Allocation[i]

Allocation algorithm:

Request[i][M] = request vector of process i
if Request[i] > Need[i]
  raise exception
if Request[i] > Available
  wait
if system would be unsafe after allocation
  wait
otherwise
  grant requested resource

Example:

resources: A = 10, B = 5, C = 7
current Available = (3, 3, 2)
    max        current    need (max - current)
P0  (7, 5, 3)  (0, 1, 0)  (7, 4, 3)
P1  (3, 2, 2)  (2, 0, 0)  (1, 2, 2)
P2  (9, 0, 2)  (3, 0, 2)  (6, 0, 0)
P3  (2, 2, 2)  (2, 1, 1)  (0, 1, 1)
P4  (4, 3, 3)  (0, 0, 2)  (4, 3, 1)

File System--Interface

Basic File Operations

Unix-like (Posix)

fd = open(fname, O_RDONLY)

fd = open(fname, O_WRONLY, S_IRUSR|S_IWUSR)

n = read(fd, array_buf, n_read)

n = write(fd, array_buf, n_write)

close(fd)