Investigating Deadlocks
Investigating Deadlocks
Investigating Deadlocks
Introduction
Objectives
At the end of this lab you should be able to:
Basic Theory
Process deadlocks which are created when processes require
access to more than one resource (not-sharable) are frequent
occurrences in a modern operating system (OS). The OS can
employ various techniques for avoiding, preventing or resolving
process deadlocks which will allow the system to run as efficiently
as possible.
1. Four processes are running. They are called P1 to P4.There are also four
resources available (only one instance of each). They are named R0 to R3.
At some point of their existence each process allocates a different resource
for use and holds it for itself forever. Later each of the processes request
another one of the four resources. Draw the resource allocation graph for a
four process deadlock condition. Do not continue until you do this and get it
verified by the tutor.
2. In the compiler window, enter the following source code in the compiler
source editor area (under PROGRAM SOURCE frame title).
program DeadlockPN
resource(X, allocate)
wait(3)
resource(Y, allocate)
for n = 1 to 20
next
end
The above code creates a program which attempts to allocate two
resources for itself. After the first allocation it waits for 3 seconds and tries
to allocate another resource. Finally it counts from 1 to 20 in a loop and
then terminates. Other than that it does nothing sensible or useful!
Now follow the instructions below as faithfully as you can:
a. Copy the above code and paste it in three more edit windows so that
you have a total of four pieces of source code.
b. In each case change N in the program name to 1 to 4, e.g.
DeadlockP1, DeadlockP2, etc.
c. Look at your graph you constructed in (1) above and using that
information fill in the values for each of the Xs and Ys in the four
pieces of source code.
d. Compile each one of the four source code.
e. Load in memory the four pieces of code generated.
f. Now switch to the OS simulator.
g. Create a single instance of each of the programs. You can do this by
double-clicking on each of the program names in the PROGRAM LIST
frame under the Program Name column.
h. In the SCHEDULER frame select Round Robin (RR) scheduling
policy in the Policies tab.
i. In OS Control tab, push the speed slider up to the fastest speed.
j. Select the Views tab and click on the VIEW RESOURCES button.
k. Select Stay on top check box in the displayed window.
l. Back in the OS Control tab use the START button to start the OS
scheduler and observe the changing process states for few seconds.
m. Have you got a deadlock condition same as you constructed in (1)
above? If you havent then check and if necessary re-do above. Do not
proceed to (n) or (3) below until you get a deadlock condition.
n. If you have a deadlock condition then click on the SHOW
DEADLOCKED PROCESSES button in the System Resources