Operating System [CS 604]
Fall Semester 2006
Assignment No. 5
Total Marks: 25 Dead line: 29-12-2006
Do your own work. If two solutions are found similar, no credit will be allocated to any
of the students. Write to the point answer of the following question.
Consider the following system snapshot using the data structures in
the Banker's
algorithm, with resources A, B, C, and D, and processes P0 to P4:
Max Allocation Need Available
A B C D A B C D A B C D A B C D
P0 7 0 2 1 4 0 0 1
P1 1 6 5 0 1 1 0 0
P2 3 3 4 6 1 0 4 5
P3 1 5 6 2 0 4 2 1
P4 2 4 3 2 0 3 1 2 3 2 2 1
Using the Banker's algorithm, answer the following questions. While
executing the Banker's algorithm, if there are multiple processes that
may complete on a given cycle, please choose the one with the lowest
index.
(b) (3 pts) How many resources of type A, B, C, and D are there?
{A, B, C, D} = 9, 10, 9, 10
(c) (5 pts) What are the contents of the Need matrix?
Solution:
Need
A B C D
P0 3 0 2 0
P1 0 5 5 0
P2 2 3 0 1
P3 1 1 4 1
P4 2 1 2 0
(d) (5 pts) Is the system in a safe state? Why?
Yes, we can satisfy system in this order: P0, P4, P2, P1, P3 (this is not
the only
order, but the one you should have given). The available resources as
these processes complete are as follows:
Available
A B C D
Before 3 2 2 1
After P0 7 2 2 2
After P4 7 5 3 4
After P2 8 5 7 9
After P1 9 6 7 9
After P3 9 10 9 10
Note that the last line matches the numbers of part b.
(e) (5 pts) If a request from process P2 arrives for additional resources
of
(0,2,0,0), can the Banker's algorithm grant the request
immediately? Why?
Show the new system state and other criteria.
This state is not safe. P0 can be satisfied, but the available resources
at that point (7 0 2 2) cannot satisfy the needs of the remaining
processes.
Here is the full state description:
Max Allocation Need Available
A B C D A B C D A B C D A B C D
P0 7 0 2 1 4 0 0 1 3 0 2 0
P1 1 6 5 0 1 1 0 0 0 5 5 0
P2 3 3 4 6 1 2 4 5 2 1 0 1
P3 1 5 6 2 0 4 2 1 1 1 4 1
P4 2 4 3 2 0 3 1 2 2 1 2 0 3 0 2 1
(f) (5 pts) Given the original state (from parts a-d), if a request from
process P4 arrives for additional resources of (0,2,0,0), can the
Banker's algorithm grant the request immediately? Why?
No. P4 has not reserved enough of resource B to ask for 2 more.
Therefore, the
Banker's algorithm would reject the request outright.