Vous êtes sur la page 1sur 3

Tutorial 3 Deadlock

SCSR2043 (Operating Systems)


1.

Given the following Resource-Allocation Graph (RAG) as in Figure 1, identify set for
edges, E.
R1

P1

P2

P0

P3

R2

Figure 1: Resource-Allocation Graph


2.

State 2 methods for deadlock recovery.

3.

i)

What are the necessary conditions fro a deadlock to occur? Elaborate your answer.

ii)

When is a system in a safe state?

4.

Consider a system with 4 processes P0 through P3, 3 resource types A, B, and C, and the
current state at t0 as shown in Table 1. Hint: Safety algorithm and Resource-request
algorithm in Appendix 1.

Resource type A has 11 instances

Resource type B has 8 instances

Resource type C has 6 instances


Table 1: Process allocation
Process
P0
P1
P2
P3

Allocation
A
B
C
2
0
0
3
1
2
2
1
1
1
3
1

A
4
5
2
1

Max
B
2
3
3
4

C
1
5
2
5

i)

Calculate the Need parameter for each process based on Table 1.

ii)

Execute the safety algorithm to determine either the system is in safe or unsafe
state and write the safe sequence (if safe state). Show all your workings.

iii)

Assume P1 request 1 additional resource instance of resource type B and 1


instance of resource type C. Using resource-request algorithm and safety
algorithm, identify if P1 requests can be fulfilled by determining the new safe
sequence.

iv)

Show all your workings.

After P1s request is fulfilled in question (iii), P3 makes the following request,
Request3 = (0, 0, 1). Can the system grant the request of P3 using resource-request
algorithm and safety algorithm? Explain your answer.

5.

Consider a system with 4 processes P0 through P3, 3 resource types A, B, and C, and the
current state at t0 as shown in Table 2. Hint: Safety algorithm and Resource-request
algorithm in Appendix 1.
Table 2: Process allocation
Process
P0
P1
P2
P3
Total

A
0
1
2
0

Max
B
0
7
3
6

C
1
5
5
5

Allocation
A
B
C
0
0
1
1
0
0
1
3
5
0
6
3
2
9
9

Available
A
B
C

i)

How many resources are there of type (A, B, C)?

ii)

What is the contents of the Need matrix?

iii)

Is the system in a safe state? Why?

iv)

If a request from process P1 arrives for additional resources of (0, 5, 2), can the
Banker's algorithm grant the request immediately?

v)

What would be the new system state after the allocation (Table 3)?

Table 3: Process allocation


Process
P0
P1
P2
P3
Total

A
0
1
2
0

Max
B
0
7
3
6

C
1
5
5
5

Allocation
A
B
C

Available
A
B
C

APPENDIX 1
Safety Algorithm
1.

2.

Let Work and Finish be vectors of length m and n,


respectively.
Initialize:
Work = Available
Finish[i] = false for i= 1, 2, , n
Find an index i such that both
Finish[i] == false
Need Work
i

3.

4.

If no such i exists, go step 4.


Work = Work + Allocation
i

Finish[i] == true
Go to step 2.
If Finish[i] == true for all i then the system in
safe state.
Resource-Request Algorithm

1.

If Requesti Needi, go to step 2.


Otherwise, raise an error condition since the
process has exceeded its maximum claim.

2.

If Requesti Available, go to step 3.


Otherwise, Pi must wait since the resources are not
available.

3.

Have the system pretend to have allocated the


requested resources to process Pi by modifying the
state as follows:
Available := Available - Requesti
Allocationi := Allocationi + Requesti
Needi := Needi Requesti

4.

Execute the safety algorithm (Figure B.5) on a new


state. If the resulting state is safe, allocate the
resources, else delay the request.

Vous aimerez peut-être aussi