• 沒有找到結果。

Deadlocks

在文檔中 OPERATING SYSTEM CONCEPTS (頁 35-39)

30 Chapter 8 Deadlocks

such a deadlock occur? If it is not, why not? What deadlock scheme would seem best to eliminate these deadlocks (if any are possible), or what condition is violated (if they are not possible)?

Answer: No answer.

8.4 Consider the traffic deadlock depicted in Figure 8.11.

a. Show that the four necessary conditions for deadlock indeed hold in this example.

b. State a simple rule that will avoid deadlocks in this system.

Answer: No answer.

8.5 Suppose that a system is in an unsafe state. Show that it is possible for the processes to complete their execution without entering a deadlock state.

Answer: No answer.

In a real computer system, neither the resources available nor the demands of processes for resources are consistent over long periods (months). Resources break or are replaced, new processes come and go, new resources are bought and added to the system. If deadlock is controlled by the banker’s algorithm, which of the following changes can be made safely (without introducing the possibility of deadlock), and under what circumstances?

a. Increase Available (new resources added)

b. Decrease Available (resource permanently removed from system)

c. Increase Max for one process (the process needs more resources than allowed, it may want more)

d. Decrease Max for one process (the process decides it does not need that many re-sources)

e. Increase the number of processes f. Decrease the number of processes Answer: No answer.

8.6 Prove that the safety algorithm presented in Section 8.5.3 requires an order of mn2 op-erations.

Answer: No answer.

8.7 Consider a system consisting of four resources of the same type that are shared by three processes, each of which needs at most two resources. Show that the system is deadlock-free.

Answer: Suppose the system is deadlocked. This implies that each process is holding one resource and is waiting for one more. Since there are three processes and four resources, one process must be able to obtain two resources. This process requires no more resources and, therefore it will return its resources when done.

8.8 Consider a system consisting of m resources of the same type, being shared by n processes.

Resources can be requested and released by processes only one at a time. Show that the system is deadlock-free if the following two conditions hold:

a. The maximum need of each process is between 1 and m resources b. The sum of all maximum needs is less than m + n

Answer: Using the terminology of Section 7.6.2, we have:

Answers to Exercises 31

a. Pni = 1 Maxi < m + n b. Maxi  1 for all i

Proof: Needi = Maxi ; Allocationi If there exists a deadlock state then:

c. Pni = 1 Allocationi = m

Use a. to get:PNeedi + P Allocationi = PMaxi < m + n Use c. to get:

P

Needi + m < m + n Rewrite to get:Pni = 1 Needi < n

This implies that there exists a process Pi such that Needi = 0. Since Maxi  1 it fol-lows that Pihas at least one resource that it can release. Hence the system cannot be in a deadlock state.

8.9 Consider a computer system that runs 5,000 jobs per month with no deadlock-prevention or deadlock-avoidance scheme. Deadlocks occur about twice per month, and the operator must terminate and rerun about 10 jobs per deadlock. Each job is worth about $2 (inCPU time), and the jobs terminated tend to be about half-done when they are aborted.

A systems programmer has estimated that a deadlock-avoidance algorithm (like the banker’s algorithm) could be installed in the system with an increase in the average execu-tion time per job of about 10 percent. Since the machine currently has 30-percent idle time, all 5,000 jobs per month could still be run, although turnaround time would increase by about 20 percent on average.

a. What are the arguments for installing the deadlock-avoidance algorithm?

b. What are the arguments against installing the deadlock-avoidance algorithm?

Answer: No answer.

8.10 We can obtain the banker’s algorithm for a single resource type from the general banker’s algorithm simply by reducing the dimensionality of the various arrays by 1. Show through an example that the multiple-resource-type banker’s scheme cannot be implemented by individual application of the single-resource-type scheme to each resource type.

Answer: No answer.

8.11 Can a system detect that some of its processes are starving? If you answer “yes,” explain how it can. If you answer “no,” explain how the system can deal with the starvation prob-lem.

Answer: No answer.

8.12 Consider the following snapshot of a system:

Allocation Max Available

A B C D A B C D A B C D

P0 0 0 1 2 0 0 1 2 1 5 2 0

P1 1 0 0 0 1 7 5 0

P2 1 3 5 4 2 3 5 6

P3 0 6 3 2 0 6 5 2

P4 0 0 1 4 0 6 5 6

Answer the following questions using the banker’s algorithm:

a. What is the content of the matrix Need?

32 Chapter 8 Deadlocks

b. Is the system in a safe state?

c. If a request from process P1arrives for (0,4,2,0), can the request be granted immedi-ately?

Answer: No answer.

8.13 Consider the following resource-allocation policy. Requests and releases for resources are allowed at any time. If a request for resources cannot be satisfied because the resources are not available, then we check any processes that are blocked, waiting for resources. If they have the desired resources, then these resources are taken away from them and are given to the requesting process. The vector of resources for which the waiting process is waiting is increased to include the resources that were taken away.

For example, consider a system with three resource types and the vector Available initialized to (4,2,2). If process P0asks for (2,2,1), it gets them. If P1asks for (1,0,1), it gets them. Then, if P0 asks for (0,0,1), it is blocked (resource not available). If P2 now asks for (2,0,0), it gets the available one (1,0,0) and one that was allocated to P0(since P0is blocked).

P0’s Allocation vector goes down to (1,2,1), and its Need vector goes up to (1,0,1).

a. Can deadlock occur? If so, give an example. If not, which necessary condition cannot occur?

b. Can indefinite blocking occur?

Answer:

a. Deadlock cannot occur because preemption exists.

b. Yes. A process may never acquire all the resources it needs if they are continuously preempted by a series of requests such as those of process C.

8.14 Suppose that you have coded the deadlock-avoidance safety algorithm and now have been asked to implement the deadlock-detection algorithm. Can you do so by simply using the safety algorithm code and redefining Maxi = Waitingi + Allocationi, where Waitingiis a vector specifying the resources process i is waiting for, and Allocationi is as defined in Section 8.5 Explain your answer.

Answer: No answer.

在文檔中 OPERATING SYSTEM CONCEPTS (頁 35-39)