Vous êtes sur la page 1sur 10

Operating Systems 3 Deadlocks

Solutions
Course lectured by Prof. Gabriel Kuper Lab assist. Ilya Zaihrayeu http://www.dit.unitn.it/~ilya/os.htm

Problem 1 Q: Is it possible to have a deadlock involving

only one process? Explain your answer A: No. This follows directly from the hold and wait condition
Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes

Ilya Zaihrayeu

Operating Systems Course

Problem 2 Q: A distributed system using mailboxes has two interprocess communication primitives, SEND and RECEIVE. The latter primitive specifies a process to receive from, and blocks if no message from that process is available, even though messages may be waiting from other processes. There are no shared resources, but processes need to communicate frequently about other matters. Is deadlock possible? If it is, give an example. If not, then why?
Ilya Zaihrayeu Operating Systems Course

Problem 2, contd
A: Deadlock is possible. Assume a system of 3 processes, A, B and C. When the system starts, all mailboxes are empty. Now let A send a message to B and await a reply from B. Then let B send a message to C and await a reply. Finally, let C send a message to A and await a reply. We now have a circular wait condition and a deadlock
Ilya Zaihrayeu

3. Send (C, MC)

4. Recv (C, M)

A
1. Send (B, MB)

A
2. Recv (B, M)

5. Send (A, MA)

C B

6. Recv (A, M)

Operating Systems Course

Problem 3
Q: Consider the following snapshot of a system (given bellow) Answer the following questions using Banker's algorithm: a. What is the content of the matrix Need? b. Is the system in a safe state? c. If a request from process P1 arrives for (0,4,2,0), can the request be granted immediately ?
Allocation A B C D 0 0 1 2 1 0 0 0 1 3 5 4 0 6 3 2 0 0 1 4 MAX B C 0 1 7 5 3 5 6 5 6 5 Available A B C D 1 5 2 0

Process P0 P1 P2 P3 P4

A 0 1 2 0 0

D 2 0 6 2 6

Ilya Zaihrayeu

Operating Systems Course

Problem 3, contd
A: a. Need = Max Allocation. The matrix is shown bellow on the left-hand side; b. Yes, a sequence <P3, P4, P2, P1, P0> is safe; c. Yes, there is a sequence <P0, P2, P1, P4, P3> which is safe. The snapshot of the system after resources allocation is given bellow on the right-hand side.
Need A B C D 0 0 0 0 0 7 5 0 1 0 0 2 0 0 2 0 0 6 4 2
Ilya Zaihrayeu

Process P0 P1 P2 P3 P4

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


6

Operating Systems Course

Problem 4
Q: A system has four processes and five allocatable resources. The current allocation and maximum needs are given bellow What is the smallest value of x for which this is a safe state based on the Bankers algorithm?
Allocation B C D 0 2 1 0 1 1 1 0 1 1 1 1 MAX Available E A B C D E A B C D E 1 1 1 2 1 1 0 0 x 1 1 0 2 2 2 1 0 0 2 1 3 1 0 0 1 1 2 2 1
Operating Systems Course

Process P0 P1 P2 P3

A 1 2 1 1

Ilya Zaihrayeu

Problem 4, contd
A: The matrix Need as shown on the right. If x is 0, then we have an unsafe state immediately If x is 1, then P3 can run, after it Process releases resources, P0 can run, P0 after P2 and then P1, i.e. P1 sequence <P3, P0, P2, P1> is P2 safe, thus the system is in the P3 safe state Therefore the minimal value of x is 1

Need A B C D E 0 1 0 0 0 0 2 1 0 0 1 0 3 0 0 0 0 1 1 1

Ilya Zaihrayeu

Operating Systems Course

Problem 5
Q: Suppose that process P0 on the figure bellow requests the last tape drive. Does this action lead to a deadlock? Explain your answer

Proc ess Tape drive s Plott ers Print ers CD-R oms

Proc ess Tape drive s Plott ers Print ers CD-R oms

drive s Tape

P0 3 0 1 1 P1 0 1 0 0 P2 1 1 1 0 P3 1 1 0 1 P4 0 0 0 0 Allocated Resources
Ilya Zaihrayeu

P0 1 1 0 0 P1 0 1 1 2 P2 3 1 0 0 P3 0 0 1 0 P4 2 1 1 0 Resources still needed


Operating Systems Course

6 3 4 2 Existing resources

Print ers CD-R oms


9

Plott er

Problem 5, contd
A: The snapshot of the system after P0 takes the last tape drive is shown bellow There is a safe sequence of processes: <P3, P0, P1, P2, P4> thus the system is in a safe state no deadlock possible
Proc ess Tape drive s Plott ers Print ers CD-R oms Proc ess Tape drive s Plott ers Print ers CD-R oms drive s drive s Tape Print ers CD-R oms Tape Plott er Plott er Print ers CD-R oms
10

P0 4 0 1 1 P1 0 1 0 0 P2 1 1 1 0 P3 1 1 0 1 P4 0 0 0 0 Allocated Resources
Ilya Zaihrayeu

P0 1 1 0 0 P1 0 1 1 2 P2 3 1 0 0 P3 0 0 1 0 P4 2 1 1 0 Resources still needed

6 3 4 2 Existing resources

0 0 2 0 Available resources

Operating Systems Course

Vous aimerez peut-être aussi