133.63K

week13_exercise

1.

Week 12 OS exercises
Banker’s Algorithm Simulator

2.

Exercise 1: Exploring Safe and Unsafe States
Objective: Understand safe and unsafe states and the impact of resource allocation.
1. Scenario:
• Total Resources: {A: 10, B: 5, C: 7}
• Initial State:
P1
Max {A: 7, B: 5, C: 3}
Allocation {A: 0, B: 1, C: 0}
P2
Max {A: 3, B: 2, C: 2}
Allocation {A: 2, B: 0, C: 0}
P3
Max {A: 9, B: 0, C: 2}
Allocation {A: 3, B: 0, C: 2}
P4
Max {A: 2, B: 2, C: 2}
Allocation {A: 2, B: 1, C: 1}
P5
Max {A: 4, B: 3, C: 3}
Allocation {A: 0, B: 0, C: 2}

3.

Exercise 1: Exploring Safe and Unsafe States
2. Tasks:
• Enter the scenario in the simulator.
• Identify if the system is in a safe state.
• Experiment by making small requests for resources for each process and observe the
impact on the system's safety.
• Document one example where the system remains safe and one where it becomes
unsafe.

4.

Exercise 2: Designing Resource Requests
Objective: Practice creating resource requests that maintain system safety.
1. Scenario:
• Total Resources: {A: 5, B: 3, C: 3}
• Initial State:
P1
Max {A: 3, B: 2, C: 2}
Allocation {A: 1, B: 0, C: 1}
P2
Max {A: 2, B: 1, C: 1}
Allocation {A: 1, B: 1, C: 0}
P3
Max {A: 4, B: 2, C: 2}
Allocation {A: 0, B: 0, C: 0}
2. Tasks:
• Propose a resource request for each process that keeps the system in a safe state.
• Test your proposals using the simulator and verify if the system remains safe.
• For a chosen process, make a larger-than-necessary request and document why
the simulator denies it or marks the system as unsafe.

5.

Exercise 3: Deadlock Avoidance in Action
Objective: Explore how to avoid deadlock by following the Banker's Algorithm rules.
1. Scenario:
• Total Resources: {A: 6, B: 4, C: 2}
• Initial State:
P1
Max {A: 5, B: 3, C: 2}
Allocation {A: 1, B: 1, C: 1}
P2
Max {A: 3, B: 2, C: 1}
Allocation {A: 2, B: 1, C: 0}
P3
Max {A: 2, B: 1, C: 1}
Allocation {A: 0, B: 1, C: 0}
2. Tasks:
• Incrementally allocate resources to processes.
• Test different sequences of allocations and document which ones lead to
deadlock and which avoid it.
• Explain why some sequences are safer than others.

6.

Challenge 1: Recovering from Deadlock
Objective: Understand deadlock recovery by analyzing resource allocation.
1. Scenario:
• Total Resources: {A: 5, B: 4, C: 3}
• Deadlocked State:
P1
Max {A: 4, B: 3, C: 2}
Allocation {A: 2, B: 2, C: 1}
P2
Max {A: 3, B: 2, C: 1}
Allocation {A: 2, B: 1, C: 1}
P3
Max {A: 2, B: 1, C: 1}
Allocation {A: 1, B: 1, C: 1}
Available: {A: 0, B: 0, C: 0}

7.

Challenge 1: Recovering from Deadlock
2. Tasks:
• Identify which processes can have resources preempted or terminated to recover
from the deadlock.
• Simulate the recovery process using the tool.
• Write a short report explaining the steps taken to break the deadlock.

8.

Challenge 2: Creating Scenarios
Objective: Create and test custom scenarios to analyze system safety and deadlock
conditions.
Your task is to design a Banker's Algorithm scenario and test its behavior using the Banker's
Algorithm Simulator.
1. Create a scenario with the following specifications:
• Total resources for 3 types (e.g., {A, B, C}).
• At least 3 processes, each with:
• Maximum resource requirements (Max) for each resource type.
• Initial allocated resources (Allocation).
• Ensure the total maximum resource requirements for each type (Σ Max) do not
exceed the total available resources.

9.

Challenge 2: Creating Scenarios
2. Answer the following questions based on your scenario:
• Is the system in a safe state initially? Why or why not?
• Provide an example of a resource request sequence that keeps the system safe.
• Can you create a sequence that leads to an unsafe state or deadlock? If yes, explain
how it happens.

10.

Challenge 3: Maximizing Throughput
Objective: Optimize resource allocation for maximum efficiency.
1. Scenario:
• Total Resources: {A: 7, B: 6, C: 4}
• Initial State:
P1
Max {A: 5, B: 3, C: 2}
Allocation {A: 2, B: 1, C: 1}
P2
Max {A: 3, B: 2, C: 2}
Allocation {A: 1, B: 0, C: 1}
P3
Max {A: 4, B: 3, C: 1}
Allocation {A: 0, B: 2, C: 0}
Available: {A: 0, B: 0, C: 0}
2. Tasks:
• Experiment with allocation sequences that maximize the number of
completed processes.
• Explain why your allocation sequence is optimal.

11.

Deliverables
• You must submit the following in written form as your assignment:
1. The scenario you designed (including Total resources, Max, and Allocation).
2. Screenshots and results from the simulator demonstrating your findings.
3. A detailed written explanation addressing the questions above, including your
observations and conclusions.
English     Русский Rules