Tutorial 5
Tutorial 5
TUTORIAL 5
DEADLOCK & STARVATION
Question1
A system has 32MB of user memory and a disk, CD_ROM and a line printer attached
to it. Two processes A and B, with the size of 8MB and12MB are currently in the
memory. Process A requests and gets the CD-ROM. It is currently writing something
to the device. Process B also requests for the CD-ROM.
ii) Can the CD-ROM be allocated to Process B before A finishes? Explain your
answer.
Question2
For each of the situation, state whether a deadlock exist. Explain your answer.
(Note: You are required to pay attention to the words in bold)
i) A system has 32MB of user memory and a printer attached to it. Two
processes A and B, with the size 32MB each want to print something.
Process A requests and gets the printer, then starts to compute the
values to print. Before it has finished with its computation, it exceeds its
time quantum and is swapped out. Process B now runs and tries to
acquire the printer.
Tutorial 4 Page 1
Answer: Although process A is swapped off the storage as the quantum time
elapsed for process B is to take place, process A still retains the printer, and
process B still requires the printer. In this case, however, a deadlock occurs.
ii) Assume three processes, A, B and C, are competing for three resources: R, S, T.
At the beginning all three processes holds nothing. The following sequence
of processes takes place:
1. A requests R
2. B requests S
3. C requests T
4. A requests S
5. B requests T
6. C requests R
Answer: Process A requests R and gets it. Process B requests S and gets it. Process C
requests T and gets it.At starting, none of the processes hold anything however, as
each subsequent process request for the other resources, none of them are releasing
their current resource before requesting for another. So, a deadlock consists here as
given by the directed graph in below:
Tutorial 4 Page 2
Questi
on 3
Answer: For scanning a text, the scanner is assigned to P1. P1 can get a text
scanner. Although none of the services can be left wasted preferably, P2 is
designed to request and receive a CD recorder. However, as P2 keeps it, P1
requests a CD recorder and P2's Scanner request is blocked since it is set as P1. A
deadlock takes place.
Question 4
Consider a system with seven processes, P1 through P7, and six resources, R1
through R6. The state of which resources are currently owned and which ones
are currently being requested is as follows:
1. Process P1 holds R1 and wants R2
2. Process P2 holds nothing but wants R3
3. Process P3 holds nothing but wants R2
4. Process P4 holds R4 and wants R2 and R3
5. Process P5 holds R3 and wants R5
6. Process P6 holds R6 and wants R2
7. Process P7 holds R5 and wants R4
In the system above, which processes are in a state of deadlock? Explain why the
processes you have identified are in a state of deadlock.
Tutorial 5 Page 3
Answer:
Step by step all processes for resources are described:
1. Process P1 holds R1, wants R2 and gets it (based on First Come First Serve
rule).
2. Process P2 does not hold, wants R3 but ignored as P5 is holding it.
3. Process P3 also does not hold, wants R2 but ignored as P1 is holding it.
4. Process P4 holds R4, wants R2 and R3 but ignored as P1 is holding R2 and
P5 is holding R3.
5. Process P5 holds R3, wants R5 but ignored as P7 is holding it.
6. Process P6 holds R6, wants R2 but ignored as P1 is holding it.
7. Process P7 holds R5, wants R4 but ignored as P4 is holding it.
Question 5
For each of the situations below, explain the sequence of events that lead to a
‘deadlock’ or ‘no deadlock’.
i) Two processes P1 and P2 request to read a ‘Read-Only File’.
Answer: P1 requests a ‘Read-Only File’ and gets it.P1 reads the file and
then publications it.P2 requests the ‘Read-Only File’ and becomes it.
ii) Two processes P1 and P2 need to read and update data on a tape file and
print the result on a printer
Answer:
P1 requests a tape file to read and write data and gets it.P2 requests the
printer and gets it.P1 requests for the printer to print the updated data but
denied as P2 is holding it.P2 requests for the tape file to read and write
data to print but denied as P1 is holding it.
Tutorial 5 Page 4
Question 6
Answer:
First method would be Process P requests both the disk file and the printer at
its creation time, then copies data from the tape drive onto the disk file, sorts
it out and then print the results to a printer.
Second method is Process P is requesting both the disk file and the printer but
the OS allocates the disk file to it first. Process P copies data from the tape
drive onto the disk file and sorts it out and then releases the disk file. Only
after releasing the disk file Process P is granted allocation of the print to print
out the results.
ii) What are the TWO(2) disadvantages of the methods you described in b(i)
Answer:
1. Firstly, if Process P is granted access to all the requested resources
during the initialization but now and then uses one resource, that
reduces the degree of multi programming dramatically since too many
assigned devices would remain idle until process P requires them. If
this approach is used in interactive systems then the efficiency of the
distribution of resources in that setting would be seriously impaired.
Tutorial 5 Page 5