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

Department of Computer Science & Engineering

R.V. COLLEGE OF ENGINEERING


(AUTONOMOUS UNDER VTU)
BANGALORE-560059

Operating Systems
Assignment

Exercise problems for Chapter 8 – Deadlock


(8.1 to 8.8)

Submitted by:

Sankalp Jain

(1RV08CS096)
8.1 List three examples of deadlocks that are not related to a computer-system
environment.

Answer :

1. Two cars crossing a single lane bridge from opposite directions.


2. A person going down a ladder while another person is climbing up the ladder.
3. Two trains traveling toward each other on the same track.

8.2 Is it possible to have a deadlock involving only one single process? Explain your answer.

Answer:

No. This follows directly from the hold-and-wait condition.

8.3 People have said that proper spooling would eliminate deadlocks. Certainly, it
eliminates from contention card readers, plotters, printers, and so on. It is even possible to
spool tapes (called staging them), which would leave the resources of CPU time, memory,
and disk space. Is it possible to have a deadlock involving these resources? If it is, how
could 
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:

It is possible to still have a deadlock. Process P1 holds memory pages that are required by
process P2 , while P2 is holding the CPU that is required by P1.The best way to eliminate these
types of deadlock is to use preemption. 

8.4 Consider the traffic deadlock depicted in Figure 7.8.


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: 

a. Each section of the street is considered a resource.


Mutual-exclusion — only one vehicle on a section of the street.
Hold-and-wait — each vehicle is occupying a section of the street and is waiting to move to the
next section.
No-preemption — a section of a street that is occupied by a vehicle cannot be taken away from
the vehicle unless the car moves to the next section.
Circular-wait — each vehicle is waiting for the next vehicle in front of it to move.
Allow a vehicle to cross an intersection only if it is assured that the vehicle will not have to stop
at the intersection.

 
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:

Consider the following snapshot of the system. 


Allocation A B CD P0 00 12 P1 10 00 P2 13 54 P3 06 32 P4 00 14 
Max Available AB CD A B C D 00 12 1 5 2 0 17 50 23 56 06 52 06 56 
By allowing P1 to finish and return its resources to the Available list, we can then service the
request of P3.When P3 returns its resources, Available contains (2 8 8 6), thus allowing all of the
rest of the processes to finish in any order. 

8.6 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 resources).
e.
Increase the number of processes.
f.
Decrease the number of processes.

Answer:

a.
Anytime
b.
Only if Max demand of each process does not exceed total number of available resources, and
the system remains in a safe state.
c.
Same as (b)
d.
Anytime
e.
Anytime
f.
Anytime 

8.7 Prove that the safety algorithm presented in Section 7.5.3 requires an order of m × n2
operations.

Answer:

Step 2 may be executed n +(n -1)+(n -2)+... +3+2+1= n × (n + 1)/2 times. In each iteration, m
resource types must be examined. Therefore the algorithm requires m × n × (n +1)/2steps. 

8.8 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. 

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