0% found this document useful (0 votes)
3 views

Unit 5-Notes_OS_Part2

The document discusses deadlock in computing, defining it as a state where processes are unable to proceed because each is waiting for resources held by another. It outlines necessary conditions for deadlock, examples in both real life and computer systems, and methods for handling deadlocks, including prevention, avoidance, detection, and recovery strategies. The document also explains resource allocation graphs and the implications of resource sharing and preemption in the context of deadlock situations.

Uploaded by

himanshuwalde2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit 5-Notes_OS_Part2

The document discusses deadlock in computing, defining it as a state where processes are unable to proceed because each is waiting for resources held by another. It outlines necessary conditions for deadlock, examples in both real life and computer systems, and methods for handling deadlocks, including prevention, avoidance, detection, and recovery strategies. The document also explains resource allocation graphs and the implications of resource sharing and preemption in the context of deadlock situations.

Uploaded by

himanshuwalde2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Deadlock (UNIT-5 Part-II)

INDEX

Sr. Page No.


Topic
No.
1. Definition: Deadlock 2
Deadlock characterization (Necessary
2.
conditions for deadlock)
2
Definition: Live lock / Indefinite
3.
postponement/starvation
2
4. Sharable and non-sharable resources 3
5. Examples of deadlock in real life 3
6. Examples of deadlock in computer system 4
7. Resource use protocol 4
8. How OS manages resources 4
9. Resource allocation graph 5
10. Wait for Graph 6
11. Methods for handling deadlocks 7
12. Deadlock prevention 8
13. Deadlock avoidance 11
14. Banker’s algorithm 13
15. Safety algorithm, resource Request Algorithm 14
16. Deadlock Detection 17
17. Recovery from Deadlock 18
18. Ostrich Algorithm 18

Page No. 1
Deadlocks
Definition of Deadlock: A set of processes is in a deadlock state when every process in
the set is waiting for an event that can be caused by only other process in the set.
(Events: Resource acquisition and release).
In a deadlock processes never finish executing and system resources are tied up,
preventing other jobs from even starting.

Example of a deadlock: Two trains approaching each other on a single track.


A B
N S

• There is a cycle in
tN tS resource allocation graph.
Hence Deadlock.

A B

Train A Train B

Fig. Trains Deadlocked

Livelock /Indefinite postponement/Starvation: It is a situation in which some


processes are making progress towards completion but one or more other processes are
locked out of the resource, because there is always another (higher priority) process that
is using it. These processes are referred to be as starved.

Deadlock characterization:

Necessary conditions: a deadlock situation can arise if the following four conditions hold
simultaneously in a system.

1. Mutual exclusion: at least one resource must be held in a non sharable mode, i.e.
only one process at a time can use the resource.
2. Hold and wait: There must exist a process that is holding at least one resource and
is waiting to acquire additional resources that are currently being held by other
processes.
3. No Preemption: Resources cannot be preempted; i.e. a resource can be released
only voluntarily by the process holding it after that process has completed its task.
4. Circular wait: there must exist a set {P0, P1, P2, …,Pn} of waiting processes such
that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is
held by P2, …,Pn-1 is waiting for a resource that is held by Pn and Pn is waiting for a
resource held by P0.

Page No. 2
Qu. How the trains deadlock can be resolved?

Classification of Resources
• Sharable resources:

• Can be used by several users at the same time.


• Program code (if reentrant or pure)
• Data areas if read only.
• Non-sharable resources:

• Can only be used by one user at a time (Requires mutually exclusive access)
• Data areas that need to be written.
• Most external devices like printers.
• The processor.

Non-sharable Resources can be further classified as

• preemtable:
-- Use of resource may be preempted and restarted later on.
-- e.g. The processor , The primary memory

• non-preemptable:
-- Use of resource can not be preempted.
-- e.g. Printers. (A new document cannot be printed until the previous is completed.)

Q: Give examples of deadlock, which are not related to a computer system environment:
Ans.
a. River crossing by two goats
b. Traffic deadlock example

Figure: Traffic Deadlock Example :( Vehicle Gridlock)

Page No. 3
Here each stream of cars holds one intersection but needs another intersection before
it can proceed. Consider each intersection as a resource and each stream of cars as a
process.

1. Mutual exclusion condition applies, since only one stream of vehicles can be on an
intersection of the street at a time.
2. Hold-and-wait condition applies, since each stream of vehicles is occupying an
intersection, and waiting for another intersection.
3. No-preemptive condition applies, since an intersection that is occupied by a stream
of vehicles cannot be taken away from it.
4. Circular wait condition applies, since each stream of vehicles is waiting on the next
stream of vehicles to move. That is, each stream of vehicles in the traffic is waiting
for an intersection held by the next stream of vehicles in the traffic.

Q: Give examples of deadlock in a Computer System:

ANS:
(A) Deadlock involving single resource type: -
System with 4 tape drives and two processes, if each process holds two tape drives
but needs three, deadlock occurs.
(B) Deadlock involving different resource types: -
System with one printer and one card reader and two processes. Suppose that
process P is holding the card reader and process Q is holding the printer if P now
requests the printer and Q requests the card reader a deadlock occurs.

Qu.: a) Show that the four necessary conditions for deadlock indeed hold in the
examples (A,B) given above.
b) Come up with a simple rule that will avoid deadlocks.

ANS: Allow each process to acquire all the resources it needs in advance.

Q: How process should use a resource? (Resource use protocol)


A: Request ->Use -> Release.

Q: How OS Manages Resources?


A: The request and release of resources are system calls.
e.g. Device: request device, release device.
File: open, close.
Memory: allocate, free.
Others: with wait and signal operations on semaphores.

System wide resources allocation table is maintained by OS wherein it records


whether each resource is free or allocated, and if a resource is allocated to which
process. If a process requests a resource that is currently allocated to another process, it
can be added to a queue of processes waiting for this resource.

Page No. 4
Resource Allocation graph(RAG): It is a directed graph used to describe deadlocks
more precisely. It consists of set of vertices V and a set of edges E. the set of vertices is
partitioned into tow types.
P = {P1, P2, …, Pn}, the set containing all the processes in the system and r={R1, R2,…,
Rm}, the set consisting of all the resource types in the system.

Example(1) :
R1 R3

Assignment edge
Request edge P1 P2 P3

Instances of
R4 resource R4

R2

Above resource allocation graph depicts the following situation: -


• The sets P, R and E

P = {P1,P2,P3}
R = {R1,R2,R3,R4}
E = {P1->R1, P2->R3, R1->P2, R2->P1, R3->P3}
Request Edge Assignment edge
• Resource instances:
One instance of resource type R1
Two instances of resource type R2
One instances of resource type R3
Three instances of resource type R4
• Process states:
Process P1 holding one instance of type R2 and waiting for an instance of type R1
Process P2 holding one instance of type R2 and waiting for an instance of type R3
Process P3 holding one instance of type R3

RAG and Deadlock condition:

(1) If graph contains no cycles then no process in the system is deadlocked.


(2) Existence of a cycle is necessary and sufficient condition for deadlock; if each resource
type has exactly one instance.
(3) If each resource type has several instances then a cycle does not necessarily imply that a
deadlock occurred. In this case a cycle in the graph is necessary but not a sufficient
condition for the existence of a deadlock.

Page No. 5
Wait for graph: We obtain this graph from the resource allocation graph by removing the
nodes of type resource and collapsing the appropriate edges. In this graph we show the
processes waiting on each other.
Q1: show that request from process P3 for an instance of a resource type R2 in example 1
leads to a deadlock.
Ans.: Adding the request edge P3->R2 in example 1.
There are two cycles in the graph hence there is a chance that the given system is
deadlock.

R1 R3

P3

P1 P2 P3

P1 P2

R2 R4
Fig. Wait for graph for RAG on the left

The four necessary conditions for deadlock hold for the above graph hence the above
system is in a deadlock state.

Q2: Show that the resource allocation graph shown below is not representing a deadlock
system OR Find our whether the following system is deadlocked. Justify your answer.
Ans: As there is a cycle in the graph the system is unsafe. But it is not deadlocked because
the process P4 may release its instance of resource type R2. That resource can then be
allocated to P3, causing the circular wait/cycle to break.

R1 P2 P2 P3

P1
P3 P1 P4
R2

Fig. Wait for graph for RAG on the left


P4

Page No. 6
Q: Draw resource allocation graphs for deadlock examples A & B
Ans :

Example A Example B

Tape drives

P Q

P1 P2
Card reader Printer

Methods for handling deadlocks:

Sr. Method How


No.
1. Prevention (To ensure that • Deny one of the necessary conditions
system will never enter the
deadlock state)
2. Avoidance (To ensure that • Banker’s Algorithm (Requires
system will never enter the knowledge of request and release of
deadlock state) resources by each process),
• Resource allocation graph algorithm
(with only one instance of each resource
type.)
3. Detection and recovery Allow the system to enter the deadlock state and
then recover

4. Combined approach Divide resources into different resource classes.


For each resource class employ different
approach .
5. Ignore the problem altogether Used by most OS, Including UNIX and MS
( Ostrich Algorithm) Windows

Note: Methods 1 & 2 see that a deadlock does not occur.

Page No. 7
Deadlock Prevention:

For a deadlock to occur each of the four necessary conditions must hold. By ensuring that
at least one of these conditions cannot hold, we can prevent the occurrence of a deadlock.

1) Mutual Exclusion:
i) Shareable resources: Mutually exclusive access is not required; hence these
resources cannot be involved in a deadlock. (e.g. read only files)
ii) Non-Shareable Resources: Some resources like printer are intrinsically non
shareable. Hence mutually exclusive access is required.
Hence in general it is not possible to prevent deadlocks by denying mutual
exclusion condition.
2) Hold and wait: To deny this condition we must guarantee that whenever a process
requests a resource it does not hold any other resources. The different protocols to achieve
this are
a) Each process to request and be allocate all of its resources before it begins
execution.
b) Allow a process to request only when it has none. Here before requesting an
additional resource the process has to release any previously hold resource.

Disadvantages of denying hold and wait:

i) Resource utilization may be very low, since many of the resources


may be allocated but unused for a long period of time.
ii) Starvation is possible. A process that needs several popular resources
may have to wait indefinitely because at least one of the resources
that it needs is always allocated to some other process.

3) No Preemptions: To deny this condition following protocol observed-

a) If a process that is holding some resources, requests additional resources that


cannot be immediately allocated to it (i.e. the process must wait) then all resources
currently being held are preempted. These resources are added to the list of
resources. The process will only be restarted when it can regain its old resources as
well as the new one that it is requesting.
b) If a process requests some resources that are not available, we check whether
they are allocated to some other process that is waiting for additional resources. If
so we preempt the desired resources from the waiting process and allocate them to
the requesting process.
Some type of resources such as partial updated files, printers cannot be
preempted without corrupting the system. Therefore preemption is possible only for
certain type of resources (such as CPU & Memory), and it can be applied when the
benefits of deadlock prevention outweigh the cost of state save restore operations.

Qu.: Certain system (THE system) allows printer to be preempted from a process. Explain
How this system can eliminate the problem of corrupted printout?

Page No. 8
Ans: It can finish the current page and remember the next page number to be printed for a
process. OS can maintain a table storing process id’s and page numbers to be printed next.

4) Circular wait: In order to ensure that the circular wait condition never holds we may
impose a total ordering of different classes of system resources. In this approach system
resources are divided into different classes Cj where j=1,…,n. Deadlocks are prevented by
requiring all processes to request and acquire their resources in a strictly increasing order of
the specified system resource classes. Moreover acquisition of all resources within a given
class must be made with a single request, and not incremental. In other words once a
process acquires a resource belonging the class Cj, it can only request resources of class
Cj+1 or higher thereafter.

Ex. Two processes require one tape drive and one printer.

P1 P1

T P T (1) P(2)

P2 P2

Fig. Without resource ordering Fig. with resource ordering

In the RAG below assume that Pi is a process holding a resource in class Ci.
Process Pi cannot possibly wait for any process that is itself waiting for a resource in class
Ci or lower. Hence circular wait condition possibility is eliminated.
Wait Wait
P1 P2 P3

Wait
The type of wait shown in above figure is impossible since a process holding class 3
resources can’t wait for class 1 resource (since 3>1)

Example: 3 students are writing records with 2 ink pens 1 pencils and 1 erasure, on a
partitioned table with the slot containing these four items open for access to three persons,
as shown in figure below.

Pn Pn
Pl Er

Page No. 9
Class Number of
number instance
Ink pen 1 2
Pencil 2 1
Erasure 3 1

Let the system state without resource ordering is


Processes Max. Demand Allocation Need=MAX-Alloc
R1 R2 R3 R1 R2 R3 R1 R2 R3
S1 1 1 1 1 0 1 0 1 0
S2 1 1 1 1 0 0 0 1 1
S3 0 1 1 0 1 0 0 0 1

Pen (1) Pencil (2) Erasure (3)

S1 S2 S3

Fig. Resource Allocation graph for the above example without resource ordering

Pen (1) Pencil (2) Erasure (3)

S1 S2 S3

Fig. Resource Allocation graph for the above example with resource ordering

Page No. 10
S1 S2 S3 S1 S2 S3

Fig. Wait for graph without resource Fig. Wait for graph with resource
ordering ( Note cycle in this graph: ordering (No cycles; hence safe state)
Hence Unsafe state)

Deadlock avoidance:

i) This approach requires additional information about how resources are to be requested.
ii) With this knowledge of the complete sequence of requests and release for each process
we can decide for each request whether request can be satisfied or whether the process
must wait to avoid a possible future deadlock.

Whenever a process requests a resource that is currently available, the system must
decide if the resource can be immediately allocated or if the process must wait. The request
is granted only if it leaves the system in a safe state.
In this scheme if a process requests a resource, which is currently available, it may
still have to wait. Thus resource utilization may be lower than without a deadlock
avoidance algorithm.

Resource allocation state: It is defined by number of available and allocated resources,


and the maximum demands of the processes.

Safe, Unsafe and deadlock state spaces: -

i) Deadlock state is an unsafe state.


Unsafe ii) Not all unsafe states are deadlocks.
Deadlock iii) In an unsafe state the OS can not prevent
processes from requesting resources in
such a way that a deadlock occurs (i.e.
behavior of the process controls the unsafe
Safe state.)
iv) It is possible to go from a safe state to
unsafe state.

Safe state: A state is safe if the system can allocate resources to each process (up to it’s
maximum) in some order and still avoid a deadlock.

Page No. 11
Example: Consider a system with total 12 magnetic tape drives and three processes P0,
P1, P2. Resource allocation state of these processes is as follows (at time T0)

Process Maximum Allocations Available Need=Max- Alloc


demand =Total- Alloc (Remaining)
=12-(5+2+2)

P0 10 5 3 5
P1 4 2 2
P2 9 2 7

i) Find out whether the system is safe. (Safety Algo.)


ii) Find out (at time T1>T0) whether the system will grant the request by process P2
for one more tape drive. (Resource Request Algo.)

Ans : The content of the work vector is given as processes are allocated additional tapes.
Work=available (initially)

i) Safety Algorithm:

Work=Work+Allocation Remarks
3 Initially (At time T0)
5 P1 finished
10 P0 finished
12 P2 finished

There exists a safe sequence <P1, P0, P2>. Hence the given resource allocation state is safe.

ii) Applying resource request algo. :


Pretend that the request by P2 for one more tape drive is granted. The modified state is
shown below
Process Maximum Allocations Available Need=Max- Alloc
demand =Total- Alloc (Remaining)
=12-(5+2+3)
P0 10 5 2 5
P1 4 2 2
P2 9 3 6

Now applying safety algorithm on the above resource allocation state


Work Remarks
2 Initially (At time T0)
4 • P1 finishes
• Now no process can finish hence unsafe state, hence
the request can’t be granted.)

Page No. 12
Banker’s Algorithm: A deadlock avoidance algorithm:
The name was chosen because the algorithm could be used in banking system to ensure that
the bank never allocates its available cash in such a way that it could no longer satisfy the
needs of all its customers.

Algorithm:
i) When a new process enters the system it must declare the max number of
instances of each resource type that it may need. This number may not exceed
the total number of resources in the system.
ii) When a user process requests a set of resources, it must be determined whether
the allocation of these resources will leave the system in safe state. If so the
resources are allocated otherwise the process must wait until some other process
release enough resources.
Implementation: Let n be the number of processes in the system, let m be the number
of resource types.
Data structure required:
• Availabe: A vector of length m, indicating number of available resources of each
type.
• Max: An mxn matrix defining the max demand of each process.
• Allocation: An nxm matrix defining the no. of resources of each type currently
allocated to each process.
• Need: An nxm matrix indicating the remaining resource needs of each process.
Need [i, j] =max [i,j] – Allocation [i,j]

Qu. What do you mean by the following?


i) Available[j] = k ii)Max[i,j] = k iii) Allocation[i,j] = k
iv) Need[i,j] = k

Example: - Consider a system with five processors {p0, p1, p2, p3, p4} and three resource
types {A, B, C}. Resource type A has 10 instances, B has 5, C has 7 instances.
Suppose that at time T0 following snapshot of system is taken.
Total = [10 5 7] , Available=[10 5 7] – [7 2 5] = [3 3 2]
Find out whether the system is in a safe state.

Process Max Allocation Available= Need=Max- Work Comment


demand ABC Total-Alloc Alloc
ABC (Remaining)
ABC
p0 753 010 332 743 332 = Available
p1 322 200 122 532 p1 finished
p2 902 302 600 743 p3 finished
p3 222 211 011 745 p4 finished
p4 433 002 431 755 p0 finished
Total 725 10 5 7 p2 finished

Page No. 13
As finish[i]=true for all i , the system is in a safe state. ( See the algorithm below)

Safety Algorithm: Resource request algorithm


1) Let work and finish be vectors of If Requesti be the request vector for process Pi If
length m and n respectively. Requesti [j] = k, then process Pi wants k instances of
Initialize work = Available and resource type Rj, when a request for resource is made by
Finish[i] = false for i=1,2,…,n. process Pi, the following actions are taken.
2) Find an i such that both a. 1) If Requesti <= Needi , goto step 2 otherwise
a)Finish[i]=false raise an error condition since the process has
b)Need[i] <= Work exceeded its maximum claim.
if no such i exists then go to step 4. 2) If Requesti <= Available goto step 3 otherwise
3) Work=Work+Allocationi Pi must wait since the resources are not
Finish[i]=true available.
Goto step 2 3) Let the system pretend that the requested
4) If Finish[i] = true for all i then the resources are allocated to process Pi by
system is in safe state. modifying the state, as follows:

(Time Complexity m*n2 ) Availablei = Availablei-Requesti;


Allocationi = Allocationi + Requesti;
Needi = Needi - Requesti

4) Now apply the safety algorithm to find


whether the system is in safe state. If the
resulting resource allocation state is safe the
transaction is completed and process Pi is
allocated its resources. However if the new state
is unsafe, then Pi must wait for Requesti and the
old state is restored.

Programming Assignment:
Simulate the Banker’s Algorithm for deadlock avoidance using a Computer program

Page No. 14
Deadlock avoidance for resource allocation system with only one instance
of each resource type( using resource allocation graph algorithm).

In addition to the request and assignment edges, we introduce a new type of edge, called
the claim edge.
Claim edge A claim edge Pi->Rj indicates that process P1 may request resource Rj at some
time in the future. This edge resembles the request edge in direction, but is represented by a
dashed line.
R1
R1 Suppose P2 requests R2,
claim edge is P2->R2 P1 P2
P1 P2 converted to assignment
edge R2->P2, as this R2
R2
results in a cycle the
request is not granted. Fig. An unsafe state in
Fig. Resource allocation resource allocation graph
graph for deadlock avoidance

Page No. 15
Deadlock Detection: If a system does not employ either a deadlock prevention or
deadlock avoidance algorithm then a deadlock situation may occur. In this environment,
the system may provide:
• An algorithm that examines the state of the system to determine whether a
deadlock has occurred.
• An algorithm to recover from the deadlock.
Deadlock Detection for resource allocation system with single instance of each
resource type:

Q3: Show that the following system is in the deadlock state.

P5

R1 R3 R4

P1 P2 P3

R2 P4 R5

Ans: Converting the above graph to wait for graph.

P5

Note: An algorithm to detect a


P1 P2 P3 cycle in a graph requires an order
of n2 operations, where n is
number of vertices in the graph.
P4

This is an example of resource allocation system with single instance of each resource type.
Hence the presence of cycle in the graph shows that the system is deadlocked.

Deadlock detection in system with several instances of a resource type

The algorithm uses additional data structure ‘Request which is an n*m matrix. It indicates
the current request of each process. If Request [i,j] =k then process Pi is requesting k more
instances of resource type Rj.

Page No. 16
Example (a): Consider a system with resources A, B, C with instances 7,2 and 6
respectively. Suppose that at time T0 we have the following resource allocation state.

State Alloc Request Available/Work Comments


ABC ABC ABC
P0 010 000 000 Initially
P1 200 202 010 P0 finished
P2 303 000 313 P2 finished
P3 211 100 524 P3 finished
P4 002 002 526 P4 finished
Total 726 726 P1 finished
Applying detection algorithm, we now claim that the resource allocation state is not in a
deadlock state. Indeed if we execute our algorithm, we will find that the sequence
< P0,P2,P3,P4,P1> will result in Finish[i] = true for all.

(b) Suppose that process P2 makes one additional request for an instance of type C. The
request matrix is modified as follows:
After this for no
Request Available/Work process
ABC ABC Requesti <= Work
P0 000 000 Initially Hence we claim that
P1 202 010 P0 finished system is now
P2 001 deadlocked and
P3 100 processes involved are
P4 002 P1,P2,P3 and P4

The algorithm (Deadlock Detection)

1. Let Work and Finish be vectors of length m and n respectively.


Initialize Work := Available. For i = 1,2,…,n, if Allocationi != 0, then Finish[i] :=
false; otherwise Finish [i] = true
/*only processes holding resources (Allocationi != 0) can be involved in a deadlock
hence making Finish[i] := false only for such processes.*/
2. Find an index i such that both
a) Finish[i] = false
b) Requesti <= Work
If no such i exists goto to step 4
3. Work := Work + Allocationi
Finish [i]: =true
Goto step 2.
4. If finish[i] = false, for some i, 1<=i<=n, then the system is in a deadlock state.
Moreover if Finish [i] = false, then process Pi is deadlocked.

Page No. 17
Ex. 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.

Detection algorithm uses:

When should we invoke the detection algorithm?


1. If deadlocks occur frequently, then the detection algorithm algorithm should be
invoked frequently.
2. In the extreme we can invoke the detection algorithm every time a request for
allocation can not be granted immediately
3. A less expensible alternative is simply to invoke the algorithm at less frequent
intervals - for example once per hour or whenever CPU utilization drops below
40 %.

Example: (Deadlock detection)


Consider the given resource allocation graph.

R1 R2

P0 P1 P2 P3

Total
R1 R2 R3 R3
2 3 2
i) find if the system is in deadlock state
ii) Otherwise find a safe sequence

Solution: Applying deadlock algorithm


Process Allocation Request Available Work Comment
R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3
P0 1 1 0 1 0 0 0 0 1 0 0 1 Initially
P1 1 0 1 0 1 1 0 1 1 P2 finished
P2 0 1 0 0 0 1 1 1 2 P1 finished
P3 0 1 0 1 2 0 2 2 2 P0 finished
2 3 2 P3 finished

From the above table it is clear that the system is not in a deadlock state, since there exists
a safe sequence < P2,P1P0,P3 >.

Page No. 18
Recovery from deadlock:
1. process termination
• Abort all deadlocked processes.
• Abort one process at a time untill the deadlock cycle is eliminated.
2. Resource preemption: To eliminate deadlocks using resource preemption we
successfully preempt some resources from processes and give these resources to other
processes until the deadlock cycle is broken.

Issues:
• Selecting a victim (no. of resources a process is holding, amount of time a process
has consumed so far during its execution)
• Rollback (Total, Partial)
• Starvation (Some process is always picked up as a victim: Select a victim based on
no. of rollbacks of a process.)

The Ostrich algorithm:


“Stick your head in the sand and pretend that there is no problem.”
• The easiest way to deal with the problem
• How is it possible to use such an algorithm?
• Other errors are much more frequent
• To not add limitations to the operating system
• The ostrich algorithm is both Windows and UNIX approved, because most users
would prefer an occasional deadlock to a very restrictive, inconvenient, complex
and slow system.

Ex. 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 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 P0 asks for (2,2,1), it gets them. If P1 asks 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
P0 is 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 you answer “yes”, give an example. If you answer “no,”
specify which necessary condition cannot occur.
b. Can indefinite blocking occur? Explain your answer.

Ans:
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 P0.

Page No. 19

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy