Description

King Saud University
College of Computer and Information Sciences
Information Technology Department
First Semester 1432/1433
IT 421
Assignment #7
Model Answer
Homework policy:
1) Copying any part of other people's code, solution sets, or from any other sources is
strictly prohibited.
2) If your source is the web, write your references in details.
3) Solutions quality (understandable and organized document, not handwriting).
Q1) Given the following state for the Banker’s Algorithm.
ã
ã
5 proces

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.

Related Documents

Share

Transcript

King Saud University College of Computer and Information Sciences
Information Technology Department
First
Semester
1432/1433
IT 421
Assignment #7 Model Answer
Homework policy:
1) Copying any part of other people's code, solution sets, or from any other sources is strictly prohibited. 2) If your source is the web, write your references in details. 3) Solutions quality (understandable and organized document, not handwriting).
Q1)
Given the following state for the Banker’s Algorithm.
ã
5 processes
P
0
through
P
4
ã
3 resource types
A
(6 instances),
B
(9 instances) and C (5 instances).
ã
Snapshot at time T
0
:
Max
Allocation
A B CA B C P
0
6 7 3
1 1 1
P
1
2 2 2
1 1 2
P
2
2 6 3
0 3 0
P
3
2 2 2
2 1 1
P
4
4 6 3
1 1 1
a)
Calculate the available vector.
Available
A B C
1 2 0
b)
Calculate the Need matrix.
Need
A B C P
0
5 6 2
P
1
1 1 0
P
2
2 3 3
P
3
0 1 1
P
4
3 5 2
c)
Is the system in a safe state? If so, show one sequence of processes which allows the system to complete. If not, explain why.
Show your computation step-by-step; otherwise, you will receive no credit. 1.
Initialize the
Work
and
Finish
vectors.
Work
=
Available
= (1, 2, 0)
Finish
= (false, false, false, false, false)
2.
Find index
i
such that
Finish
[
i
] = false and
Need
i
<=
Work i Work
=
Work
+
Allocation
i
Finish
1 (1, 2, 0) + (1, 1, 0) = (2, 3, 0) (false, true, false, false, false)
3.
At this point, there does not exist an index
i
such that
Finish
[
i
] = false and
Need
i
<=
Work
. Since
Finish
[
i
]
≠
true for all
i
, hence the system is not in a safe state.
d)
Given the request (1, 2, 0) from Process P
2
. Should this request be granted? Why or why not?
Show your computation step-by-step; otherwise, you will receive no credit.
1.
Check that
Request
2
<=
Need
2
. Since (1, 2, 0) <= (2, 3, 3), hence, this condition is satisfied. 2.
Check that
Request
2
<=
Available
. Since (1, 2, 0) <= (1, 2, 0), hence, this condition is satisfied. 3.
Modify the system’s state as follows:
Available
=
Available
–
Request
2
= (1, 2, 0) – (1, 2, 0) = (0, 0, 0)
Allocation
2
=
Allocation
2
+
Request
2
= (0, 3, 0) + (1, 2, 0) = (1, 5, 0)
Need
2
=
Need
2
–
Request
2
= (2, 3, 3) – (1, 2, 0) = (1, 1, 3)
4.
Apply the safety algorithm to check if granting this request leaves the system in a safe state. 1. Initialize the
Work
and
Finish
vectors.
Work
=
Available
= (0, 0, 0)
Finish
= (false, false, false, false, false) 2. At this point, there does not exist an index
i
such that
Finish
[
i
] = false and
Need
i
<=
Work
. Since
Finish
[
i
]
≠
true for all
i
, hence the system is not in a safe state. Therefore, this request from process
P
2
should not be granted.
Q2)
A system has three processes (P
1
, P
2
, P
3
) and three reusable resources (R
1
, R
2
, R
3
). There is one instance of R
1
, two instances of R
2
and three instances of R
3
. P
1
holds an R
1
and an R
3
and is requesting an R
2
. P
2
holds an R
3
and is requesting an R
1
and an R
2
. P
3
holds two R
2
and an R
3
and is requesting an R
1
.
a)
Draw the resource allocation graph for this situation.
P
1
P
2
P
3
R
1
R
2
R
3
b)
Write all the cycle(s) in the graph. P3->R1->P1->R2(1st instance)->P3 P3->R1->P1->R2(2nd instance)->P3
c)
Does a deadlock exist? Why? Yes, a deadlock does exist. P
3
is waiting for an instance of R
1
, the only instance of which is held by P
1
and P
1
is waiting for an instance of R
2
, both instances of which are held by P
3
. Since neither an instance of R
1
nor that of R
2
will ever become available, hence, neither P
1
nor P
3
will ever be able to continue executing. Therefore, a deadlock exists.
Q3)
A computer has three commonly used resources designated A, B and C. Up to three processes designated X, Y and Z run on the computer and each makes periodic use of two of the three resources.
Process X acquires A, then B, uses both and then releases both.
Process Y acquires B, then C, uses both and then releases both.
Process Z acquires C, then A, uses both and then releases both. a) If
two
of these processes are running simultaneously on the machine, can a deadlock occur? If so, describe the deadlock scenario. No deadlock is possible since one of the two processes will always be able to run to completion. b) Describe a scenario in which deadlock occurs if all
three
processes are running simultaneously on the machine. All three processes make their first acquisition then hang waiting for a resource that will never become available. As a specific example, a deadlock will occur if the following sequence of events occurs:
X acquires A and requests B.
Y acquires B and requests C.
Z acquires C and requests A. c)Modify the algorithm for acquiring resources so that deadlock cannot occur with three processes running. If we change Z to acquire A then C, no deadlock can occur.

Search

Similar documents

Tags

Related Search

We Need Your Support

Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks