Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 48

Jawad Shaf

jawadshaf@ciitlahore.edu.pk
Assistant Professor CS
COMSATS Institute of Information Technology,
Lahore

May 30, 2015

Computer Science Department- CIIT

May 30, 2015

Computer Science Department- CIIT

Operating System Concepts

May 30, 2015

Computer Science Department- CIIT

May 30, 2015

Computer Science Department- CIIT

Operating System Concepts

Operating System Concepts

Operating System Concepts

Operating System Concepts

Operating System Concepts

Operating System Concepts

Draw a resourceallocation graph


The sets P, R, and E:

Operating System Concepts

Resource instances:

One instance of resource type R1


Two instances of resource type R2

One instance of resource type R3


Three instances of resource type R4

Operating System Concepts

Operating System Concepts

Operating System Concepts

Deadlock prevention
is a set of methods for ensuring that at least

one of the necessary conditions (Slide 7)


cannot hold.

Operating System Concepts

Operating System Concepts

Mutual Exclusion
The

mutual-exclusion condition must hold for


nonsharable resources. For example, a printer
cannot be simultaneously shared by several
processes. Sharable resources, on the other hand,
do not require mutually exclusive access, and thus
cannot be involved in a deadlock. Read-only files
are a good example of a sharable resource. If
several processes attempt to open a read-only file
at the same time, they can be granted
simultaneous access to the file. A process never
needs to wait for a sharable resource.
Operating System Concepts

Operating System Concepts

Deadlock avoidance
on the other hand, requires that the operating

system
be given in advance additional information
concerning which resources a process will
request and use during its lifetime.

Operating System Concepts

May 30, 2015

Computer Science Department- CIIT

22

May 30, 2015

Computer Science Department- CIIT

23

May 30, 2015

Computer Science Department- CIIT

24

May 30, 2015

Computer Science Department- CIIT

25

May 30, 2015

Computer Science Department- CIIT

26

May 30, 2015

Computer Science Department- CIIT

27

May 30, 2015

Computer Science Department- CIIT

28

May 30, 2015

Computer Science Department- CIIT

29

Possible states are


Deadlock No forward progress can be made.
Unsafe state A state that may allow

deadlock.
Safe state A state is safe if a sequence of
processes exist such that there are enough
resources for the first to finish, and as each
finishes and releases its resources there are
enough for the next to finish.

Operating System Concepts

Page 254_
To illustrate, we consider a system with 12

magnetic tape drives and 3 processes: Po, PI,


and P2. Process Po requires 10 tape drives,
process PI may need as many as 4, and
process P2 may need up to 9 tape drives.
Suppose that, at time to, process Po is holding
5 tape drives, process PI is holding 2, and
process PZ is holding 2 tape drives. (Thus,
there are 3 free tape drives.)

Operating System Concepts

At time to, the system is in a safe state. The

sequence <PI, PO, P2> satisfies the safety


condition, since process PI can immediately be
allocated all its tape drives and then return
them (the system will then have 5 available
tape drives), then process Po can get all its
tape drives and return them (the system will
then have 10 available tape drives), and
finally process P2 could get all its tape drives
and return them (the system will then have all
12 tape drives available).

Operating System Concepts

A system may go from a safe state to an unsafe

state. Suppose that, at time tl, process P2


requests and is allocated 1 more tape drive. The
system is no longer in a safe state. At this point,
only process PI can be allocated all its tape
drives. When it returns them, the system will
have only 4 available tape drives. Since process
Po is allocated 5 tape drives, but has a maximum
of 10, it may then request 5 more tape drives.
Since they are unavailable, process Po must wait.
Similarly, process P2 may request an additional 6
tape drives and have to wait, resulting in a
deadlock.
Operating System Concepts

Our mistake was in granting the request from

process P2 for 1 more tape drive. If we had


made P2 wait until either of the other
processes had finished and released its
resources, then we could have avoided the
deadlock.

Operating System Concepts

Page 273

Operating System Concepts

May 30, 2015

Computer Science Department- CIIT

36

May 30, 2015

Ciit, Deft of CS-LHR

Operating System Concepts

Operating System Concepts

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 (in CPU 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 bankers algorithm) could be installed in
the system with an increase in the average
execution 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.
Operating System Concepts

a. What are the arguments for installing

the deadlock-avoidance algorithm?


b. What are the arguments against

installing the deadlock-avoidance


algorithm?

Operating System Concepts

An argument for installing deadlock avoidance


in the system is that we could ensure dead
lock would never occur. In addition, despite
the increase in turnaround time, all 5,000 jobs
could still run.
An argument against installing deadlock
avoidance software is that deadlocks occur
infrequently and they cost little when they do
occur.

Operating System Concepts

We have 5 processes, i.e., P0 through P4, and 3


resource types: A (10 instances), B (5
instances), and C (7 instances). The snapshot
of the system at time T0 is
Allocation
Max Available
ABC
ABC
ABC
P0
P1
P2
P3
P4

010
200
302
211
002

7
3
9
2
4

5
2
0
2
3

3
2
2
2
3

Operating System Concepts

332

Can request for (1, 2, 3) by P0 be granted? If

yes, what will be the sequence?


Can request for (1, 0, 2) by P0 be granted? If
yes, what will be the sequence?
Can request for (0, 3, 0) by P0 be granted? If
yes, what will be the sequence?

Operating System Concepts

(1, 2, 3) cannot be granted because it is

greater than the available resources.


Yes, it can be granted by the sequence <P1,
P3, P4, P0, P2>
(0, 3, 0) cannot be granted because the
available will then become (3, 0, 2) which
cannot satisfy any other request

Operating System Concepts

Consider the scenario below and justify

whether there is a deadlock or not.

Operating System Concepts

No deadlock, because
R1 is allocated to P2, which is not part of the
cycle.
Also R2 is allocated to P4, which is not part of
the cycle.
so once the resources are released by P2 and/or
P4, they can be allocated to P1 and P3.

Operating System Concepts

Questions ??
?
Operating System Concepts

You might also like