Vous êtes sur la page 1sur 5

Question 2: Consider the following state for the Bankers algorithm.

There are six processes (P0-P5) and


four resource types (15 instances of R0, 6 instances of R1, 9 instances of R2, and 10 instances of R3). There
are no outstanding unsatised requests for resources. Is this system state safe? Show your work (i.e., in
addition to the sequence if it exists, show how the Available (working array) changes as each process
terminates).

Answer: The system is safe. There are multiple solutions for the given situation. However, we consider
one such solution now. Before proceeding with the solution, it would be useful to ascertain the NEED
matrix. For the given problem, the NEED matrix is calculated as,

NEED Matrix:

Process A B C D
P0 2 3 3 1
P1 7 5 3 4
P2 2 1 2 2
P3 3 4 3 3
P4 3 4 4 2
P5 4 1 2 1

AVAILABLE Matrix:

Available
R0 R1 R2 R3
6 3 5 4

A safe sequence is P0, P2, P3, P4, P5 and P1.

After P0 finishes, the available matrix is,
Available
R0 R1 R2 R3
7 3 5 5

After P2 finishes, the available matrix is,
Available
R0 R1 R2 R3
7 4 6 6




After P3 finishes, the available matrix is,
Available
R0 R1 R2 R3
8 4 7 7

After P4, finishes, available matrix is,
Available
R0 R1 R2 R3
12 5 9 7

After P5 finishes, available matrix is,
Available
R0 R1 R2 R3
13 6 7 9

After P1 executes, the available matrix is,
Available
R0 R1 R2 R3
15 6 9 10

The above matrix is nothing but the maximum instances available under each category.

(b) If a request from P3 arrives for (3,2,3,3), can that request be granted? Why or why not?

Answer: Lets us ASSUME that the request can be granted. Therefore the new need matrix would become,

Process A B C D
P0 2 3 3 1
P1 7 5 3 4
P2 2 1 2 2
P3 0 2 0 0
P4 3 4 4 2
P5 4 1 2 1

and the availability matrix now is,

Available
R0 R1 R2 R3
3 1 2 1

The state is UNSAFE! The request should not be granted.



Reason:
There arent enough R0 resources to satisfy processes P1 & P5.
There arent enough resources of R1 to satisfy needs of processes P0, P1, P3 and P4
There arent enough resources of R2 to meet demands of P0, P1 & P4.
There arent enough resources of R3 to meet requirements of P1, P2 & P4.

(c) When does an unsafe state correspond to a deadlock? When does it not?

Answer: An unsafe state may fall into deadlock state, when there are two processes, whose demand can
only be satisfied when another process releases its held resource and vice-versa (only when the available
quantity of resource does not satisfy the need) in short CIRCULAR WAIT.

That is, assume that process P1 requires 5 units of resources and available is that of 4. So P1 would wait.
Similarly if process P2 requires 6 units of resources, then it needs to wait until P1 completes which would
release all the resources it has held so that it could run. This puts P2 in wait state. Now P1 waits until P2
gets completed and P2 waits until P1 gets completed. They both are never going to happen resulting in
deadlock.

When an additional request by a particular process is granted, such that the system state transfers from
SAFE to UNSAFE, but does not result in circular wait explained above, then the system state would be in
UNSAFE condition and is not deadlock.


Question 3: Consider a system consisting of four processes and a single resource. The current state of the
claim and allocation matrices are:

Claim matrix:

Process Name Maximum Need
P0 2
P1 7
P2 9
P3 3

Availability Matrix:

Process Name Available Units
P0 1
P1 2
P2 3
P3 1

What is the minimum number of units of the resource needed to be available for this state to be safe?

Answer: Currently there are 7 units available in the system. Now we need to determine additional units
required to make the system stable.

Let us begin so by adding 1 additional unit to system. This would make process P0 to run and would return
all of its held resources. Thus we have 2 resources in system. This is sufficient for process P3 to start. Upon
its completion, all the resources will be released. Now process P2 requires 6 units of additional resources
and that of process P1 requires 4 additional units.

So instead of adding 1 unit, if we had added 3 units in addition then, total number of resources after P0
execution would have been 4. This is sufficient for P3 to start. Upon its termination, we would have 5
available resources. Now P1 requires a maximum of 7 units. Already 5 resources are available in system,
P1 by itself has 2, thus making it to start its execution. Upon termination, we would now be left with 7
units of resources. P2 has 3 available resources and system has 7. But P2 requires only 9 units. Thus it can
comfortably starts its execution and terminate fine. Therefore upon completion of all processes, the
system gets back 10 units.

Thus the additional units required = 10 7 = 3 units.


Question 5: Consider the exponential average formula used to predict the length of the next CPU burst.
What are the implications of assigning the following values to the parameters used by the algorithm?
a) = 0 and 0 = 100milliseconds
b) = 0.99 and 0 = 10milliseconds

Answer: The formula to predict next CPU burst is,

n+1 = tn + (1 ) n

Substituting the values we get,

n+1 = 0 + 1* n i.e. n+1 = n

(a) Therefore, for n = 0, we have 0 = 100 milliseconds, thus, 1 is also equal to 100 milliseconds.
Generalizing, we could see from formula that, a value of 100 milliseconds is always predicted for next CPU
burst.

(b) Similarly, substituting for the given values, we could observe that, the most recent behavior of the
process is given much higher importance than the past values. Expanding the above equation to n terms,
we get,

n+1 = tn + (1 ) n-1 +.+ (1 )
j
n-j ++(1 )
n+1
0

As we could see that, as value of n increases in the power term of (1 ), the expression approximately
reduces to 0. Therefore, past estimated values arent used for calculation for CPU burst, rather, current
value is given much higher importance. This could also be termed as memory-less system, as it doesnt
keep track of previous values.



Question 6: Suppose that three concurrent processes exist in the system, as described in the following
table:

Processes Threads within Process
P1 T11, T12, T13, T14, T15
P2 T21, T22
P3 T31, T32, T33


Suppose that the system uses preemptive, round-robin scheduling, and that T11 is running when the
scheduling quantum expires. For each of the following implementations of threads, explain which threads
might possibly be executing at the beginning of the next quantum and why:

(a) Pure ULTs:

Answer: T21, T22 or T31, T32, T33

Since under a pure ULT, the OS is not aware of threads within the process i.e. multiple threads are treated
as single threads only.

(b) pure KLTs.

Answer: Any thread except T11

In this case, the kernel has full knowledge of the users thread and will make a decision.

Vous aimerez peut-être aussi