You are on page 1of 4

PUGHALL VHARSHAN A/L MAHANDREN

2TSI
Assignment 3

1. Name computer resources that essential for modern personal computer.


 CPU
 Memory
 CD-ROM
 Printer
 Speaker
 A record within a file
 A shared variable

2. There are certain books that divide resources to certain types such as
preemptable resources, non-preemptable resources, exclusive resource and
shared resources. What does all these different types of resources mean and
give at least ONE (1) example for each resource types.
 Preemptable resource
o Resource that can be taken away from a process e.g. CPU can
be taken away from processes in user space
 Non-preemptable resource
o Taking it away will cause processes to fail e.g. Disk, files
 Exclusive resource
o Only one process at a time can use it e.g. loudspeaker,
processor
 Shared resource
o Can be used by multiple processes e.g. memory, bandwidth

3. Give THREE (3) state/order on how process utilize resources.


 Request
 Use
 Release

4. Give examples of deadlock that you may encounter while using your personal
computer.
 Deadlocks may occur when two or more queries are run on
a database. Transactional databases lock active records, preventing
other queries from accessing them. If a process cannot access a
locked record, a database deadlock may occur.
5. List all FOUR (4) characterizations or conditions that are necessary to achieve
deadlock.
 Mutual Exclusion - At least one resource must be held in a non-
sharable mode(exclusive resource); If any other process requests this
resource, then that process must wait for the resource to be released.
 Hold and Wait - A process must be simultaneously holding at least
one resource and waiting for at least one resource that is currently
being held by some other process.
 No preemption - Once a process is holding a resource ( i.e. once its
request has been granted ), then that resource cannot be taken away
from that process until the process voluntarily releases it.
 Circular Wait - There must be a circular chain of two or more
processes, each waiting for a resource held by the previous member
of the chain. E.g: A set of processes { P0, P1, P2, . . ., PN } must exist
such that every P[ i ] is waiting for P[ ( i + 1 ) % ( N + 1 ) ]. ( Note that
this condition implies the hold-and-wait condition, but it is easier to
deal with the conditions if the four are considered separately. )

6. Determine the following Resource Allocation Graph whether it is in deadlock


condition or not. Explain your answer using any suitable algorithm and name
the algorithm that you used.

Allocation Need
R1 R2 R1 R2
P1 0 1 1 0
P2 1 0 0 0
P3 1 0 0 1
P4 0 1 0 0

Available [R1 R2] = [0 0] – no available instances


P1 need [1 0] so it cannot execute
So continue to P2 which does not need any resources so it can execute
Than Available will take the allocation of P2
Available = [0 0 ] + [1 0] = [1 0] next execution will be P3
P3 need [0 1] instances but Available now [1 0] so P3 cannot execute
P4 does not need any resources so it can execute
Than Available will take the allocation of P4
Available = [1 0] + [0 1] = [1 1]
P1 could execute since there are enough allocation for it to execute that available
will take allocation of P1
Available = [1 1] + [ 0 1] = [1 2]
P3 need [0 1] instances and available is enough for it to execute so there is
no deadlock Process sequence <P2 P4 P1 P3>
Safe state using Bankers algorithm

7. a. Draw RAG using the following information:


i. There are process P1, P2, P3 and P4
ii. There are resources R1 and R2 with two instances each
iii. Process P1 holds resource R2 and waiting for R1
iv. Process P2 hold resources R1
v. Process P3 holds resource R1 and waiting for R2
vi. Process P4 holds R2

b. define whether it is in deadlock condition or not. Explain your answer using


any suitable algorithm and name the algorithm that you used.

The answer same as in 6 = just to make sure students know that questions
could be the other way round

8. Using the following information about resource usage


i. Complete the chart by calculating the Max matrix
ii. By using banker algorithm demonstrate that the system is in a safe state,
write the process sequence and conclude your findings.

ALLOCATION NEED AVAILABLE MAX


PROCESS
A B C A B C A B C A B C
P0 0 1 0 7 4 3 2 3 0 7 5 3

P1 3 0 2 0 2 0 3 2 2

P2 3 0 2 6 0 0 9 0 2

P3 2 1 1 0 1 1 2 2 2

P4 0 0 2 4 3 1 4 3 3

1. Starting available is [2 3 0].


2. Go to P0. It needs [7 4 3], process cannot be executed.
3. Go to P1. It needs [0 2 0], process can be executed.
4. The new available is [5 3 2]. Calculation: [2 3 0] + [3 0 2].
5. Go to P2. It needs [6 0 0], process cannot be executed.
6. Go to P3. It needs [0 1 1], process can be executed.
7. The new available is [7 4 3]. Calculation: [5 3 2] + [2 1 1].
8. Go to P4. It needs [4 3 1], process can be executed.
9. The new available is [7 4 5]. Calculation: [7 4 3] + [0 0 2].
10. Go back to P0 and execute the process.
11. The new available is [7 5 5]. Calculation: [7 4 5] + [0 1 0].
12. P2 can be executed now with enough available resources.
Process sequence <P1 P3 P4 P0 P2>
There is no deadlock because all the processes can be processed

You might also like