0% found this document useful (0 votes)
18 views10 pages

Nebil Cover3

The document discusses 5 processes running on a system with 3 resource types. It provides the allocation, maximum needs, and current needs of each process. It then analyzes whether specific resource requests by processes P4 and P0 can be granted based on the safety algorithm.

Uploaded by

Nebil MH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views10 pages

Nebil Cover3

The document discusses 5 processes running on a system with 3 resource types. It provides the allocation, maximum needs, and current needs of each process. It then analyzes whether specific resource requests by processes P4 and P0 can be granted based on the safety algorithm.

Uploaded by

Nebil MH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

AMBO UNIVERSITY

HACHALU HUNDESSA
CAMPUS
DEPARTMENT OF COMPUTER SCIENCE
OPERATING SYSTEM ASSIGNMENT
SECTION:- 1

NAME ID NO
1- NABIL MOHAMMED…………….……………..UGR/51354/13

2- SOFAN AYALEW………………………..………..UGR/51147/13

3-OUMER ABDO……………………………………..UGR/54008/13

4-ABDUREZAK AHMED…….……………………..UGR/51362/13

5-ABEBE GONFA……………………………………..UGR/50249/13

6-KUMNEGER GASHAW…………………………..UGR/50246/13

7-ADANU DERESA…………………….……………..UGR/51612/13

SUBMITTED TO: BAYISA G.


SUBMISSION DATE: 17-02-2023

1
AMBO, ETHIOPIA

1🔸 5 processes are running in the system; P0 through P4.


 They are using 3 resource types A (with 10 instances), B (with 5 instances), and C
(with 7 instances).
 At time T0, the snapshot of data structures maintained by the OS are as follows:

The system is in a safe state since the sequence < P1, P3, P4, P0, P2> satisfies
safety criteria.
Apply the safety algorithm:
Set Work (3, 3, 2) and Finish (F, F, F, F, F)
Search for a process that can terminate,

P1 can terminate, Need[1] (1, 2, 2)  Work (3, 3, 2)


Update Work to Work + Allocation[1]: (5, 3, 2), Set Finish[3] to true:
Finish (F, T, F, F, F)
Search for a process that can terminate,

P3 can terminate, Need[3] (0, 1, 1)  Work (5, 3, 2)


Update Work to Work + Allocation[3]: (7, 4, 3), Set Finish[1] to true:
Finish (F, T, F, T, F)
Search for a process that can terminate,

P4 can terminate, Need[4] (4, 3, 1)  Work (7, 4, 3)


Update Work to Work + Allocation[4]: (7, 4, 5), Set Finish[0] to true:
2
Finish (T, T, F, T, F)
Search for a process that can terminate,

P0 can terminate, Need[0] (7, 4, 3)  Work (7, 4, 5) ,


Update Work to Work + Allocation[2]: (7, 5, 5), Set Finish[2] to true:
Finish (T, T, T, T, F)
Search for a process that can terminate,

P2 can terminate, Need[2] (6, 0, 0)  Work (10, 5, 7)

Terminate Search
Since Finish contains processes that have not terminated (no safe sequence), the
above state is unsafe and the request by P0 for the resources is not granted
– P0 must wait.

A🔸Can request for (3,3,0) by P4 be granted?

Request (3, 3, 0) < Available (3, 3, 2), then continue;


Request (3, 3, 0) < Need[4] (4, 3, 1), then continue
Update the data structures as if the request is granted
Process Allocation Max Need Available
A B C A B C A B C A B C
P0 0 1 0 7 5 3 7 4 3 0 0 2
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 3 3 2 4 3 3 1 0 1

3
Apply the safety algorithm:
Set Work (0, 0, 2) and Finish (F, F, F, F, F)
Search for a process that can terminate,
No process can have its needs (Need Matrix) met by the available
resources (Available vector), that is, no Need[i]  Work.
Terminate search.
Since Finish contains processes that have not terminated, the above state is
unsafe and the request by P4 for the resources is not granted – P4 must wait.

B🔸Can request for (0,2,0) by P0 be granted?

Request (0, 2, 0) < Available (3, 3, 2), then continue;


Request (0, 2, 0) < Need[0] (7, 4, 3), then continue
Update the data structures as if the request is granted
Process Allocation Max Need Available
A B C A B C A B C A B C
P0 0 3 0 7 5 3 7 2 3 3 1 2
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1

Apply the safety algorithm:


Set Work (3, 1, 2) and Finish (F, F, F, F, F)
Search for a process that can terminate,

P3 can terminate, Need[3] (0, 1, 1)  Work (3, 1, 2)


Update Work to Work + Allocation[3]: (5, 2, 3), Set Finish[3] to true:

4
Finish (F, F, F, T, F)

Search for a process that can terminate,

P1 can terminate, Need[1] (1, 2, 2)  Work (5, 2, 3)


Update Work to Work + Allocation[1]: (7, 2, 3), Set Finish[1] to true:
Finish (F, T, F, T, F)
Search for a process that can terminate,

P0 can terminate, Need[0] (7, 2, 3)  Work (7, 2, 3)


Update Work to Work + Allocation[0]: (7, 5, 3), Set Finish[0] to true: Finish (T, T,
F, T, F)
Search for a process that can terminate,

P2 can terminate, Need[2] (6, 0, 0)  Work (7, 5, 3)


Update Work to Work + Allocation[2]: (10, 5, 5), Set Finish[2] to true: Finish (T,
T, T, T, F)
Search for a process that can terminate,

P4 can terminate, Need[4] (4, 3, 1)  Work (10, 5, 5)

Terminate Search
Since Finish contains processes that have not terminated (no safe sequence), the
above state is unsafe and the request by P0 for the resources is not granted
– P0 must wait.

5
2🔸 5 processes, P0 through P4 and three resource types A, B, and C. Resource type A
has ten instances, resource type B has five instances, and resource type C has seven
instances. Suppose that, at time T0, the following snapshot of the system has been
taken:

The content of the matrix Need is defined to be Max − Allocation and is as follows:

753–010=743
322–302=020
902–302=600
222–211=011
433–002=431

 Find a safe sequence:


To find a safe sequence we must implement safety
algorithm: Work = available = 2 3 0

Finish [5] = {False, False, False, False, False}

 P0 : Need (p0) <= work


7 4 3 <= 2 3 0--------- Finish [p0] =False

6
 P1: Need (p1) <= work
0 2 0 <= 2 3 0 -------- Finish [p1] =True
Work=work+ allocation( P1 )
=230+302
=5 3 2 ------------- new work.

 P2: Need (p2) <= work


6 0 0 <= 5 3 2 -------- Finish [p2] =False

 P3: Need (p3) <= work


0 1 1 <= 5 3 2 -------- Finish [p3] =True
Work=work+ allocation( P3 )
=532+211
=7 4 3 ------------- new work.

 P4: Need (p3) <= work


4 3 1 <= 7 4 3 -------- Finish [p4] =True
Work=work+ allocation( P4 )
=743+002
=7 4 5 ------------- new work.

 P0: Need (p0) <= work


7 4 3 <= 7 4 5 -------- Finish [p0] =True
Work=work+ allocation( P0 )
=745+010
=7 5 5 ------------- new work.
 P2: Need (p2) <= work
6 0 0 <= 7 5 5 -------- Finish [p2] =True
Work=work+ allocation( P2 )
=755+302
=10 5 7 ------------- new work.

7
WORK
A B C
P1 5 3 2
P3 7 4 3
P4 7 4 5
P0 7 5 5
P2 10 5 7

We claim that the system is currently in a safe state. Indeed, the sequence <P1,
P3, P4, P0, P2> satisfies the safety criteria.

A🔸Can request for (3,3,0) by P4 be granted?

Suppose now that process P4 requests one additional instance of resource type A
and two instances of resource type C, so Request1 = (3,3,0). We here implement
Resource-Request Algorithm:

 Is this request can be immediately granted??


• we first
• check that Request i ≤ Need i
(3,3,0) <= (4, 3, 1), ---------True
check that Request i ≤ Available that (3,3,0) ≤ (2,3,0), -------- False

You should be able to see, however, that when the system is in this state, a
request for (3,3,0) by P4 cannot be granted, since the resources are not
available.

8
B🔸Can request for (0,2,0) by P0 be granted?

Suppose now that process P0 requests one additional instance of resource type A and
two instances of resource type C, so Request2 = (0,2,0). We here implement Resource-
Request Algorithm:

 Is this request can be immediately granted??


• we first
• check that Request i ≤ Need i
(0,2,0) <= (7, 4, 3), ---------True
• check that Request i ≤ Available that (0,2,0) ≤ (2,3,0), -------- True.
• We then pretend that this request has been satisfied, and we arrive at
the following new state:
Available = Available – Request i;
=230–020
=210

Allocation i = Allocation i + Request i;


=010+020
=030

Need i = Need i – Request i;


=743–020
=723

9
Furthermore, a request for (0,2,0) by P0 cannot be granted, even though the resources
are available, since the resulting state is unsafe.

10

You might also like