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

Resource Allocation Safety Analysis

Uploaded by

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

Resource Allocation Safety Analysis

Uploaded by

anupallavib952
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

RESOURCE REQUEST ALLOCATION PROBLEMS

1. Consider following snapshot of a system. Find whether the system is in safe state? If so
give the safe sequence. If process P1 requests (0,4,2,0) resources can be granted
immediately.

Process Allocation Maximum Available


R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4
P0 0 0 1 2 0 0 1 2 1 5 2 0
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6
P3 0 6 3 2 0 6 5 2
P4 0 0 1 4 0 6 5 6

Step 1: Calculate the Need Matrix


Need = Maximum – Allocation

Jobs Need (R1 R2 R3 R4)


P0 0-0 1-0 1-1 2-2 = (0 1 0 0)
P1 1-1 7-0 5-0 0-0= (0 7 5 0)
P2 2-1 3-3 5-5 6-4= (1 0 0 2)
P3 0-0 6-6 5-3 2-2 = (0 0 2 0)
P4 0-0 6-0 5-1 6-4= (0 6 4 2)
So the Need Matrix is:

Jobs Allocation Maximum Available Need Matrix


R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4
P0 0 0 1 2 0 0 1 2 1 5 2 0 0 0 0 0
P1 1 0 0 0 1 7 5 0 1 5 3 2 0 7 5 0
P2 1 3 5 4 2 3 5 6 2 8 8 6 1 0 0 2
P3 0 6 3 2 0 6 5 2 2 14 11 8 0 0 2 0
P4 0 0 1 4 0 6 5 6 2 14 12 12 0 6 4 2
3 14 12 12
Step 2: Check system safe state using Banker's Algorithm
 Initial Available: (1, 5, 2, 0)

Check which processes can finish (Need <= Available).

1) P0: Need (0, 0, 0, 0) <= Available (1, 5, 2, 0) — True. Allocate and finish P0.

New Available = Available + Allocation(P0) = (1,5,2,0) + (0,0,1,2) = (1,5,3,2)

Safe Sequence so far: P0


2) P1:Need(0, 7, 5, 0 )<=(1, 5, 3, 2) — False

3) P2: Need (1, 0, 0, 2) <= (1, 5, 3, 2) — True. Finish P2.

New Available = (1, 5, 3, 2) + Allocation (P2) (1, 3, 5, 4) = (2, 8, 8, 6)

Safe Sequence so far: P0, P2

4) P3: Need (0,0,2,0) <= (2,8,8,6) — True. Finish P3.

New Available = (2,8,8,6) + Allocation(P3) (0,6,3,2) = (2,14,11,8)

Safe Sequence so far :P0,P2,P3

5) P4: Need (0,6,4,2) <= (2,14,11,8) — True. Finish P4.

New Available = (2,14,11,8) + Allocation(P4) (0,0,1,4) = (2,14,12,12)

Safe Sequence so far :P0,P2,P3,P4

6) P1: Need (0,7,5,0) <= (2,14,12,12) — True. Finish P1.

New Available = (2,14,12,12)+Allocation(P1)(1,0,0,0)=(3,14,12,12)

Since all processes can finish, the system is in a SAFE state. One safe sequence is: P0, P2, P3,
P4, P1.

Step 3: P1 requests (0,4,2,0). Can it be granted immediately?


First check request <= Need

for P1: Request (0,4,2,0) <= Need(P1) (0,7,5,0) — True.

Also check request <= Available (initial):


(0,4,2,0) <= (1,5,2,0) — True (note R3: 2 <= 2 allowed).

Tentatively allocate the request and test safety:

New Available=Available- Request

New Available = (1,5,2,0) - (0,4,2,0) = (1,1,0,0)

New Allocation(P1) = (1,0,0,0) + (0,4,2,0) = (1,4,2,0)

New Need(P1) = (0,7,5,0) - (0,4,2,0) = (0,3,3,0)

Jobs Allocation Available Need Matrix


R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4
P0 0 0 1 2 1 1 0 0 0 0 0 0
P1 1 4 2 0 1 1 1 2 0 3 3 0
P2 1 3 5 4 2 4 6 6 1 0 0 2
P3 0 6 3 2 2 10 9 8 0 0 2 0
P4 0 0 1 4 2 10 10 12 0 6 4 2
3 14 12 12

Run safety algorithm with updated state:

1) P0: Need (0,0,0,0) <= (1,1,0,0) — True.. Finish P0 -> Available = (1,1,0,0) + (0,0,1,2) = (1,1,1,2)

3) P1:Need(0, 3, 3, 0)<=(1, 1, 1, 2) — False.

2) P2: Need (1,0,0,2) <= (1,1,1,2) — True. Finish P2 -> Available = (1,1,1,2) + (1,3,5,4) = (2,4,6,6)

3) P3: Need (0,0,2,0) <= (2,4,6,6) — True. Finish P3 -> Available = (2,4,6,6) + (0,6,3,2) = (2,10,9,8)

5) P4: Need (0,6,4,2) <= (3,14,11,8) — True. Finish P4.->Available=(2,10,9,8)+(0,0,1,4)=(2,10,10,12)

4) P1: Need (0,3,3,0) <= (2,10,9,8) — True. Finish P1 -> Available = (2,10,10,12) + (1,4,2,0) =
(3,14,12,12)

All processes can still finish after granting the request; thus the system remains SAFE if the request is
granted.

Conclusion: The system is currently in a SAFE state. A safe sequence is: P0, P2, P3, P4, P1. The
request (0,4,2,0) by P1 CAN be granted immediately and the system will remain safe.
2. Consider following snapshot of a system. Find whether the System is in safe state? If so give
the safe sequence. If process P2 requests (0,1,1,3) resources can be granted immediately.

Process Allocation Maximum Available


R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4

P0 2 0 0 1 4 2 1 2 3 3 2 1

P1 3 1 2 1 5 2 5 2

P2 2 1 0 3 2 3 1 6

P3 1 3 1 2 1 4 2 4

P4 1 4 3 2 3 6 6 5

Step 1: Calculate Need matrix

Need=Maximum−Allocation
Process Need (R1,R2,R3,R4)
P0 (4-2, 2-0, 1-0, 2-1) = (2, 2, 1, 1)
P1 (5-3, 2-1, 5-2, 2-1) = (2, 1, 3, 1)
P2 (2-2, 3-1, 1-0, 6-3) = (0, 2, 1, 3)
P3 (1-1, 4-3, 2-1, 4-2) = (0, 1, 1, 2)
P4 (3-1, 6-4, 6-3, 5-2) = (2, 2, 3, 3)

Process Allocation Maximum Available Need


R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4

P0 2 0 0 1 4 2 1 2 3 3 2 1 2 2 1 1

P1 3 1 2 1 5 2 5 2 5 3 2 2 2 1 3 1

P2 2 1 0 3 2 3 1 6 6 6 3 4 0 2 1 3

P3 1 3 1 2 1 4 2 4 7 10 6 6 0 1 1 2

P4 1 4 3 2 3 6 6 5 10 11 8 7 2 2 3 3

12 12 8 10

Step 2: Verify Available vector

Available is given as (3, 3, 2, 1).


Let's verify total allocations:

Sum of Allocation per resource:

 R1: 2 + 3 + 2 + 1 + 1 = 9
 R2: 0 + 1 + 1 + 3 + 4 = 9
 R3: 0 + 2 + 0 + 1 + 3 = 6
 R4: 1 + 1 + 3 + 2 + 2 = 9

Total resource instances can be deduced from allocations + available:

 R1 total = Allocation sum + Available = 9 + 3 = 12


 R2 total = 9 + 3 = 12
 R3 total = 6 + 2 = 8
 R4 total = 9 + 1 = 10

Step 3: Check if system is in safe state

Initial Work = Available = (3, 3, 2, 1)

Check which processes can satisfy Need ≤ Available:

 P0 Need = (2, 2, 1, 1) ≤ (3, 3, 2, 1)? — True.

Finish P0: Available = Available + Allocation

(P0) = (3, 3, 2, 1) + (2, 0, 0, 1) = (5, 3, 2, 2)

Sequence so far: P0

Check others:

 P1 Need = (2, 1, 3, 1) ≤ (5, 3, 2, 2)? — False (Need R3=3 > 2)


 P2 Need = (0, 2, 1, 3) ≤ (5, 3, 2, 2)? — False (Need R4=3 > 2)
 P3 Need = (0, 1, 1, 2) ≤ (5, 3, 2, 2)? — True

Finish P3:

Available = Available + Allocation

(P3) = (5, 3, 2, 2) + (1, 3, 1, 2) = (6, 6, 3, 4)


Sequence: P0, P3

Check remaining:

 P4 Need = (2, 2, 3, 3) ≤ (6,6,3,4)? — True

Finish P4:

Available = (6,6,3,4) + Allocation

(P4) = (6,6,3,4) + (1, 4, 3, 2) = (7,10,6,6)

 P1 Need = (2, 1, 3, 1) ≤ (7,10,6,6)? — True

Finish P1:

Available = (7,10,6,6) + Allocation

(P1) = (7,10,6,6) + (3, 1, 2, 1) = (10, 11,8, 7)

Sequence: P0, P3, P4,P1

Check remaining:

 P2 Need = (0, 2, 1, 3) ≤ (10, 11,8, 7)? — True

Finish P2:

Available = (10, 11,8, 7) + Allocation

(P2) = (10, 11,8, 7) + (2, 1, 0, 3) = (12, 12, 8, 10)

Sequence: P0, P3, P4,P1, P2

Check remaining:

Sequence: P0, P3, P4, P1, P2


Conclusion:

 The system is in a safe state.


 A safe sequence is: P0 → P3 → P4 → P1 → P2

Step 4: Can P2's request (0, 1, 1, 3) be granted immediately?

P2 is requesting: (0, 1, 1, 3)

First check request <= Need

For P2: Request (0, 1, 1, 3) <= Need (P2) (0, 2, 1, 3) — True.

Also check request <= Available (initial):

(0,1,1,3) <= (3,3,2,1) — False (note R4: 3 <= 1 fails).

Since Request > Available (specifically R4: requested 3 but only 1 available), the request cannot
be granted immediately.

3. The operating system contains 3 resources .The number of instances of each resource type are
(7, 7, 10) the current allocation is given below.

a. Is the current allocation safe?

b. Find the need matrix.

c. can a request made by the process P1(1,1,0) can it be granted?

Process Allocation Maximum Available


R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 2 2 3 3 6 8 2 3 0
P2 2 0 3 4 3 3
P3 1 2 4 3 4 4
Step 1: Calculate Need matrix

Need=Maximum−Allocation
Process Need (R1,R2,R3)
P1 (3-2, 6-2, 8-3) = (1,4,5)
P2 (4-2,3-0,3-3) = (2,3,0)
P3 (3-1,4-2,4-4) = (2, 2, 0)

Process Allocation Maximum Available Need


R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3

P1 2 2 3 3 6 8 2 3 0 1 4 5

P2 2 0 3 4 3 3 4 3 3 2 3 0

P3 1 2 4 3 4 4 5 5 7 2 2 0

7 7 10

Step 3: Check if system is in safe state

Initial Work = Available = (2,3,0)

Check which processes can satisfy Need ≤ Available:

 P1 Need = (1,4,5) ≤ (2,3,0)? — False.


 P2 Need=(2,0,3) ≤ (2,3,0)? —True.

Finish P2: Available = Available + Allocation

(P2) = (2,3,0) + (2,2,3) = (4,3,3)

Sequence so far: P2

 P3 Need=(2,2,0) ≤ (4,3,3)? —True.

Finish P3: Available = Available + Allocation

(P3)=(4,3,3)+(1,2,4)=(5,5,7)

Sequence so far: P2,P3


 P1 Need= (1,4,5) ≤((5,5,7) —True.

Finish P3: Available = Available + Allocation

(P1)=(5,5,7)+(2,2,3)=(7,7,10)

Sequence so far: P2, P3, P1

Therefore Safe Sequence is P2, P3, P1

Apply Resource Request Allocation

Step 1: Request ≤ Need

P1(1, 1, 0) ≤(1, 4, 5) —True.

Step 2: Request ≤ Available

P1(1, 1, 0) ≤ (2, 3, 0) —True.

Step 3: Available=Available-Request

= (2, 3, 0) - (1, 1, 0)

Available = (1, 2, 0)

Allocation= Allocation + Request

= (2, 2, 3) + (1, 1, 0)

= (3, 3, 3)

Need (P1)= Need(P1)-Request(P1)

= (1, 4, 5) - (1, 1, 0)

Need (P1) = (0, 3, 5)


Process Allocation Maximum Available Need
R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3

P1 3 3 3 3 6 8 1 2 0 0 3 5
P2 2 0 3 4 3 3 2 3 0
P3 1 2 4 3 4 4 2 2 0

Apply Banker’s Safety Algorithm.

 P1 Need = (0, 3, 5) ≤ (1, 2, 0)? — False.


 P2 Need= (2, 3, 0) ≤ (1, 2, 0)? — False.
 P3 Need= (1, 2, 4) ≤ (1, 2, 0)? — False.

After applying Banker’s algorithm .The requested resources made by P1 (1, 1, 0) cannot be
granted immediately and the system is not in safe state.

Assignment

1.A system consists of 5 jobs(J1,J2,J3,J4,J5) 3 resources R1,R2,R3 Resources R1 has 10


instances of resource type R2 has 5 instances ,R3 has 7 instances. The following snapshot of
system

Process Allocation Maximum Available


R1 R2 R3 R1 R2 R3 R1 R2 R3
J1 0 1 0 7 5 3 3 3 2
J2 2 0 0 3 2 2
J3 3 0 2 9 0 2
J4 2 1 1 2 2 2
J5 0 0 2 4 3 3

a) Need matrix
b) Is system is in safe state
c) If a request J1 arrives (1,0,2) can request be granted immediately?

Common questions

Powered by AI

A process request can be immediately granted if it meets two conditions: the requested resources do not exceed the process's remaining needs and are less than or equal to the currently available resources. Furthermore, upon granting the request and updating the system state, a safety algorithm projection must show that the system can still be brought to a safe state using the new allocations. As evidenced in Source 2, P1's request (0,4,2,0) meets both ≤ Need and ≤ Available conditions, and a recalculation still leaves the system in a safe sequence .

The Banker's Algorithm determines system safety by examining if the available resources can allow each process to complete given its maximum needs, proceeding to the next process if true, and updating the available resources accordingly. This is done in a sequence ensuring that, at any point in time, at least one process can run to completion using the available resources, leading to a safe state. In the example, processes are checked in the sequence P0, P2, P3, P4, and P1, confirming the system's safe state with sufficient resources for each in turn .

Applying the Banker's Algorithm after each new request is essential to continuously ensure that the system remains in a state where each process can complete without causing deadlock, thus preserving system integrity. This repeated checking adjusts the available resources dynamically and validates that strategies like safe sequencing continue to work effectively. In Sources 1 and 4, the algorithm's application post-requests ensured that the system state updates do not lead to unsafe conditions, securing operational coherence despite resource fluctuations .

To recalculate the Need matrix after a new request, you first verify if the request is less than or equal to the existing Need for that process. Then, subtract the request from both the Available resources and the process's Need, and add it to the Allocation for the process. In Source 2, when process P1 requests (0,4,2,0), the Available becomes (1,1,0,0), Allocation for P1 becomes (1,4,2,0), and its Need becomes (0,3,3,0) after recalculation .

Reassigning priority to a process request can affect queued requests by changing the order of allocation, potentially causing some requests to wait longer to ensure system safety. With priority reassignment, the safety algorithm must reassess whether each subsequent request, given the new priority environment, maintains system-wide feasibility and completion assurance, as evaluated in safety sequences like those in Sources 2 and 4, ensuring lower priority requests do not lead to unsafe states because of shifts needed for higher priority ones .

A safe sequence in resource allocation systems is a sequence of processes where each can obtain maximum resources necessary, allowing all to complete without deadlock. It is crucial for ensuring that the system can successfully execute all jobs while adhering to resource constraints. In Source 1, the safe sequence (P0, P2, P3, P4, P1) demonstrates resource assignment order that prevents system deadlock, maintaining resource balance even under additional constraints .

A process request might not be granted immediately if the requested resources exceed currently available resources, even if they satisfy the current Need condition. This is illustrated in Source 4, where P2's request (0,1,1,3) exceeds the available R4 resources (1 available), failing the immediate granting condition despite meeting the Need requirements .

Significant changes in the availability matrix due to a new resource request can jeopardize system safety by limiting resources for other processes, potentially leaving them unable to complete. The re-evaluation using the safety algorithm determines whether after making the request, enough resources remain to fulfill any outstanding process requirements according to a safe sequence. In Source 2, even after the request from P1, the system is still able to follow a sequence ensuring safety remains intact, but substantial changes could disrupt this balance .

When granting a large resource request that reduces availability, the system conducts a stepwise safety analysis to ascertain whether other processes can still proceed to completion from this new baseline. This involves recalculating needs, updating allocations, testing safe sequence viability, and ensuring the reduced availability does not prevent future completions. As shown in Sources 1 and 2, these comprehensive checks validate system state maintenance and can confirm the pre-emptive task completion assurance before granting large requests .

A system's initial resource allocation is verified by summing the allocations across all processes for each resource type and ensuring that this total, when added to the current available resources, equals the total resources declared initially for each type. This involves summing up allocations for resources such as R1, R2, and R3 and comparing against the total resource availability as depicted in Sources 3 and 4, confirming consistency .

You might also like