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

Tutorial 5

The document describes a tutorial on deadlocks and starvation. It includes several questions about identifying preemptible resources, whether a deadlock exists in different scenarios, and the conditions needed for deadlock. Key details provided in the responses include: 1) Memory is identified as the preemptible resource in the first scenario, as processes can be swapped in and out of memory. 2) A deadlock is identified in one scenario where two processes are waiting for a printer resource and neither will release it. 3) The "hold and wait" condition is described as one of the conditions needed for deadlock, where a process holds one resource while waiting for another.

Uploaded by

arman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Tutorial 5

The document describes a tutorial on deadlocks and starvation. It includes several questions about identifying preemptible resources, whether a deadlock exists in different scenarios, and the conditions needed for deadlock. Key details provided in the responses include: 1) Memory is identified as the preemptible resource in the first scenario, as processes can be swapped in and out of memory. 2) A deadlock is identified in one scenario where two processes are waiting for a printer resource and neither will release it. 3) The "hold and wait" condition is described as one of the conditions needed for deadlock, where a process holds one resource while waiting for another.

Uploaded by

arman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Tabassum Mustafa Authoy

Student ID: SUKD1902120

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.

i) Identify from the description above a pre-emptable resource. Explain


your answer

Answer: Memory is the pre-emptable property of the three properties


outlined above. Processes must be kept in memory so for such processes to
operate as well, a planning policy, such as the Round Robin Algorithm, must
be in place to interrupt the process after a certain quantum period of time
has elapsed to change another process into memory.

ii) Can the CD-ROM be allocated to Process B before A finishes? Explain your
answer.

Answer: CD-ROM is a non-preventable resource unit. When process A is


inserted on the CD-ROM to write or burn the discs inside, this can not be
prevented and switched for another process because it leads to data or file
corruption that becomes unreadable on the disc. Process A must be
completed to transfer a CD-ROM to Process B.

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

Two processes, P1 and P2 each want to record a scanned document on a CD. To


carry out the work both processes need to lock two devices: Scanner and CD
recorder. Explain how a deadlock situation might take place in the above
scenario.

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.

From processes P2 to P7 are in a state of deadlock since they are requesting


resources which are not available because of other processes using them while also
not releasing the resources that these processes are now holding.

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.

Shared resources including read-only files are often strictly reserved.


Consequently, no deadlock exists due to mutual exclusion.

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.

Systems allocation strategy provides and allocates the services available


on the basis of the order. There is nevertheless a stalemate here, because
of the assets keeping and also due to no pre-emption for equipment such
as printers. So it happens deadlock.

Tutorial 5 Page 4
Question 6

One of the conditions for a deadlock to occur is the ‘Hold-and-Wait’ condition. To


ensure that the hold-and-wait condition never holds in the system, we must
guarantee that, whenever a process requests a resource, it does not hold any other
resource.
You are given the following situation: ‘A process P copies data from a tape drive to
a disk file, sorts the disk file, and then print the results to a printer’.
i) Describe two methods of how process P request and hold the resources.

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.

2. The second drawback is that when Process P has a resource it releases


to obtain the desired resource, it will impact the Process P completion
status because it releases the present resource for a new resource, but
fails to reassign it for the next request when it is not accessible when
other processes are using it.

Tutorial 5 Page 5

You might also like