Вы находитесь на странице: 1из 6

Assignment on Deadlock

Md. Saidur Rahman Kohinoor


ID: 142-15-3669
Set: 01
Class Test Number: 02
Question:
Consider the following snapshot of a system: A, B, C and D have 10, 13, 9 & 12 instances.
Allocation
Max
A B C D A B C D
P0
0 0 1 2
3 3 1 2
P1
3 1 2 1
4 2 5 2
P2
2 1 0 3
3 4 1 6
P3
1 3 1 2
2 3 2 4
P4
1 4 3 2
3 5 6 5
(+)

---------------------

7 9 7 10

a) What is the content of the matrix Available?


Answer:
A B C D
Total
10 13 9 12
Allocated
7 9 7 10
( - ) -------------------------------------------------

Available

b) What is the content of the matrix Need?


Answer:
Need = Max Allocation
A B C D
P0
3 3 0 0
P1
1 1 3 1
P2
1 3 1 3
P3
1 0 1 2
P4
2 1 3 3
b) Is this state safe? Show this by using safety algorithm.
Answer:
Available: 3 4 2 2
Allocation
Need
A B C D
A B C D
P0
0 0 1 2
3 3 0 0
P1
3 1 2 1
1 1 3 1
P2
2 1 0 3
1 3 1 3
P3
1 3 1 2
1 0 1 2
P4
1 4 3 2
2 1 3 3

If,
Need
< Available then, Work = Available + (Allocation)i
P0 (3 3 0 0) < (3 4 2 2)
.. Work: (3 4 2 2) + (0 0 1 2) =
P3 (1 0 1 2) < (3 4 3 4)
.. Work: (3 4 3 4) + (1 3 1 2) =
P4 (2 1 3 3) < (4 7 4 6)
.. Work: (4 7 4 6) + (1 4 3 2) =
P1 (1 1 3 1) < (5 11 7 8)
.. Work: (5 11 7 8) + (3 1 2 1) =
P2 (1 3 1 3) < (8 12 9 9)
.. Work: (8 12 9 9) + (2 1 0 3) =
.. Sequence is: P0 -> P3 -> P4 -> P1 -> P2

3
4
5
8
10

4
7
11
12
13

3
4
7
9
9

4
6
8
9
12

d) If a request from process P1 arrives for (1, 1, 0, 1), what will be the systems state?
Answer:
Request: P1 (1 1 0 1)
.. (Allocation) P1
= (Allocation) P1 + (Request) P1
= (3 1 2 1) + (1 1 0 1)
=4 2 2 2
& (Available)

P0
P1
P2
P3
P4

= (Available) (Request)P1
= (3 4 2 2) (1 1 0 1)
= 2 3 2 1

Allocation
A BCD

Max
A BCD

Need
A B CD

0
4
2
1
1

3
4
3
2
3

3
0
1
1
2

0
2
1
3
4

1
2
0
1
3

2
2
3
2
2

3
2
4
3
5

1
5
1
2
6

2
2
6
4
5

3
0
3
0
1

0
3
1
1
3

0
0
3
2
3

Here, no need is less than available. So, The Request P1(1, 1, 0,1) is Not Granted.

Class Test Number: 03


1. Consider the following snapshot of a system: A, B and C have 8, 2, and 5 instances.
Allocation
Need
ABC
ABC
P0
101
110
P1
212
332
P2
300
011
P3
101
010
a) What is the content of the matrix Available?
Answer:
A B C
Total
: 8 2 5
Allocated : 7 1 4
(-) ----------------------------

Available : 1

1 1

b) What is the content of the matrix Maximum?


Answer:
Maximum = Allocation + Need
..
A B C
P0
2 1 1
P1
5 4 4
P2
3 1 1
P3
1 1 1
c) Is this state safe? Show this by using safety algorithm.
Answer:
Available: 1 1 1
Allocation
Need
ABC
ABC
P0
101
110
P1
212
332
P2
300
011
P3
101
010
Here, P1 process need is greater than Available. So, this state is Unsafe.
2. Describe the following resource allocation graph.

Answer:
R1P2:
P1R1:
R4P1:
P2R4:

Process P2 is holding one instance of resource R1.


Process P1 is requesting instance access to resource R1.
Process P1 is holding one instance of resource R4.
Process P2 is requesting instance access to resource R4.

R4P3:
R2P3:
P3R3:
R2P4:
R3P4:

Process P3 is holding one instance of resource R4


Process P3 is holding one instance of resource R2
Process P3 is requesting instance access to resource R3.
Process P4 is holding one instance of resource R2
Process P4 is holding one instance of resource R3.

Set: 02
Class Test Number: 02
1. Consider the following snapshot of a system: A, B, C & D have 3, 17, 16 & 12 instances.
Allocation
Max
A B C D
A B C D
P0
0 1 1 0
0 2 1 0
P1
1 2 3 1
1 6 5 2
P2
1 3 6 5
2 3 6 6
P3
0 6 3 2
0 6 5 2
P4
0 0 1 4
0 6 5 6
a) What is the content of the matrix Available?
Answer:
A B C D
Total
3
17 16 12
Allocated
2
12 14 12
( - ) -------------------------------------------------

Available

b) What is the content of the matrix Need?


Answer:
Need = Max Allocation
A B C D
P0
0 1 0 0
P1
0 4 2 1
P2
1 0 0 1
P3
0 0 2 0
P4
0 6 4 2
c) Is this state safe? Show this by using safety algorithm.
Answer:
Available: 1 5 2 0
Allocation
Need
A B C D
A B C D
P0
0 1 1 0
0 1 0 0
P1
1 2 3 1
0 4 2 1
P2
1 3 6 5
1 0 0 1
P3
0 6 3 2
0 0 2 0
P4
0 0 1 4
0 6 4 2
If,
Need
< Available then, Work = Available + (Allocation)i
P0 (0 1 0 0) < (1 5 2 0) .. Work: (1 5 2 0) + (0 1 1 0) =
P3 (0 0 2 0) < (1 6 3 0) .. Work: (1 6 3 0) + (0 6 3 2) =
P4 (2 1 3 3) < (1 12 6 2) .. Work: (1 12 6 2) + (0 0 1 4) =
P1 (0 4 2 1) < (1 12 7 6) .. Work: (1 12 7 6) + (1 2 3 1) =
P2 (1 0 0 1) < (2 14 10 7)
.. Work: (2 14 10 7) + (1 3 6 5) =
.. Sequence is: P0 -> P3 -> P4 -> P1 -> P2

1
1
1
2
3

6
12
12
14
17

3
6
7
10
16

0
2
6
7
12

d) If a request from process P1 arrives for (0,2,1,0), what will be the systems state?
Answer:
Request: P1 (0 2 1 0)
.. (Allocation) P1
= (1 2 3 1) + (0 2 1 0)
= 1 4 4 1
& (Available)

P0
P1
P2
P3
P4

Allocation
A B C D
0 1 1 0
1 4 4 1
1 3 6 5
0 6 3 2
0 0 1 4

= (1 5 2 0) (0 2 1 0)
= 1 3 1 0
Need
A B C
0 1 0
0 2 2
1 0 0
0 0 2
0 6 4

D
0
1
1
0
2

P0 (0 1 0 0) < (1 3 1 0) .. Work: (1
P3 (0 0 2 0) < (1 4 2 0) .. Work: (1
P4 (2 1 3 3) < (1 10 5 2) .. Work: (1
P1 (0 2 2 1) < (1 10 6 6) .. Work: (1
P2 (1 0 0 1) < (2 14 10 7)
.. Work: (2
.. Sequence is: P0 -> P3 -> P4 -> P1 -> P2

3
4
10
10
14

1
2
5
6
10

0)
0)
2)
6)
7)

+
+
+
+
+

(0
(0
(0
(1
(1

1
6
0
4
3

1
3
1
4
6

0)
2)
4)
1)
5)

=
=
=
=
=

1
1
1
2
3

4
10
10
14
17

2
5
6
10
16

0
2
6
7
12

1. Consider the following snapshot of a system: A, B and C have 10, 2, and 5 instances.
Allocation
Need
ABC
ABC
P0
101
210
P1
212
333
P2
300
101
P3
101
010
a) What is the content of the matrix Available?
Answer:
A B C
Total
: 10 2 5
Allocated : 7 1 4
(-) ----------------------------

Available :

1 1

b) What is the content of the matrix Maximum?


Answer:
Maximum = Allocation + Need
..
A B C
P0
3 1 1
P1
5 4 5
P2
4 0 1
P3
1 1 1

c) Is this state safe? Show this by using safety algorithm.


Answer:
Available: 3 1 1
Allocation
Need
ABC
ABC
P0
101
210
P1
212
333
P2
300
101
P3
101
010
Here, need of P1 process is greater than Available. So, this state is Unsafe.
2. Describe the following resource allocation graph.

Answer:
P1R1:
R1P2:
P2R4:
R4P1:

Process P1 is requesting instance access to resource R1.


Process P2 is holding one instance of resource R1.
Process P2 is requesting instance access to resource R4.
Process P1 is holding one instance of resource R4.

R4P3:
P3R3:
R3P4:
R2P3:
R2P4:

Process P3 is holding one instance of resource R4


Process P3 is requesting instance access to resource R3.
Process P4 is holding one instance of resource R3.
Process P3 is holding one instance of resource R2
Process P4 is holding one instance of resource R2

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: The End :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Вам также может понравиться