0% found this document useful (0 votes)
95 views2 pages

Case Study-Question-3

The document describes applying resource allocation and safety algorithms to determine if a request from process P2 can be granted. It is determined that: 1) P2's request satisfies the resource allocation algorithm and is granted, updating the allocation, need, and available matrices. 2) Applying the safety algorithm results in a safe sequence of <P1, P3, P4, P5, P2>. 3) Since the system is in a safe state after granting P2's request, the request can be granted.

Uploaded by

Elia
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)
95 views2 pages

Case Study-Question-3

The document describes applying resource allocation and safety algorithms to determine if a request from process P2 can be granted. It is determined that: 1) P2's request satisfies the resource allocation algorithm and is granted, updating the allocation, need, and available matrices. 2) Applying the safety algorithm results in a safe sequence of <P1, P3, P4, P5, P2>. 3) Since the system is in a safe state after granting P2's request, the request can be granted.

Uploaded by

Elia
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/ 2

Solution (iii): P2 requests (0 4 2 0) i.e.

Request[P2]= 0 4 2 0
• To decide whether the request is granted, we use Resource Request algorithm.
Step 1: Request[P2]<=Need[P2] i.e. (0 4 2 0) <= (0
7 5 2)  true. Step 2: Request[P2]<=Available i.e.
(0 4 2 0) <= (1 5 2 0)  true.
Step 3: Available = Available – Request[P2] = (1 5 2 0) - (0 4 2 0)= (1 1 0 0)
Allocation[P2] = Allocation[P2] + Request[P2] = (1 0 0 0) + (0 4
2 0)= (1 4 2 0) Need[P2] = Need[P2] – Request[P2] = (0 7 5 2) -
(0 4 2 0)= (0 3 3 2)
• We arrive at the following new system state

Allocation Max Available


A B C D A B C D A B C D
P1 0 0 1 2 0 0 1 2 1 1 0 0
P2 1 4 2 0 1 7 5 0
P3 1 3 5 4 2 3 5 6
P4 0 6 3 2 0 6 5 2
P5 0 0 1 4 0 6 5 6

• The content of the matrix Need is given by


Need = Max - Allocation
• So, the content of Need Matrix is:
Need
A B C D
P1 0 0 0 0
P2 0 3 3 2
P3 1 0 0 2
P4 0 0 2 0
P5 0 6 4 2

• Applying the Safety algorithm on


the given system, Step 1:
Initialization
Work = Available i.e. Work =1 1 0 0
....P1………P2…….P3………..P4… ..P5….
Finish = | false | false | false | false | false |

Step 2: For i=1


Finish[P1] = false and Need[P1]<=Work i.e. (0 0 0 0)<=(1 1 0 0)  true
So P1 must be kept in safe sequence.
Step 3: Work = Work + Allocation[P1] =(1 1 0 0)+(0 0
1 2)=(1 1 1 2)
....P1………
P2…….P3……...P4.....
. P5…
Finish = | true | false | false | false | false |

Step 2: For i=2


Finish[P2] = false and Need[P2]<=Work i.e. (0 3 3 2)<=(1 1 1 2) false
So P2 must wait.

Step 2: For i=3


Finish[P3] = false and Need[P3]<=Work i.e. (1 0 0 2)<=(1 1 1 2)  true
So P3 must be kept in safe sequence.
Step 3: Work = Work + Allocation[P3] = (1 1 1 2)+(1 3 5 4)=(2 4 6 6)
....P1……P2……….P3…….P4… ....P5….
Finish = | true | false | true | false | false |

Step 2: For i=4


Finish[P4] = false and Need[P4]<=Work i.e. (0 0 2 0)<=(2 4 6 6)  true
So P4 must be kept in safe sequence.
Step 3: Work = Work + Allocation[P4] =(2 4 6 6)+(0 6 3 2)=(2 10 9 8)
....P1………P2…….P3…….P4…….P5….
Finish = | true | false | true | true | false |

Step 2: For i=5


Finish[P5] = false and Need[P5]<=Work i.e. (0 6 4 2)<=(2 10 9 8)  true
So P5 must be kept in safe sequence.
Step 3: Work = Work + Allocation[P5] =(2 10 9 8)+(0 0 1 4)=(2 10 10 12)
....P1………P2…….P3…….P4……P5….
Finish = | true | false | true | true | true |

Step 2: For i=2


Finish[P2] = false and Need[P2]<=Work i.e. (0 3 3 2) <=(2 10 10 12) 
true
So P2 must be kept in safe sequence.
Step 3: Work = Work + Allocation[P2] =(2 10 10 12)+(1 4 2 0)=(3 14 12 12)
....P1………P2……P3…….P4……P5….
Finish = | true | true | true | true | true |

Step 4: Finish[Pi] = true for 0<=i<=4


Hence, the system is currently
in a safe state. The safe
sequence is <P1, P3, P4, P5,
P2>.
Conclusion: Since the system is in safe sate, the request can be granted.

You might also like