0
0
Operating Systemsknowledge~10 mins

Deadlock avoidance (Banker's algorithm) in Operating Systems - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the maximum resource matrix in Banker's algorithm.

Operating Systems
max_resources = [[7, 5, 3], [3, 2, [1]], [9, 0, 2]]
Drag options to blanks, or click blank then click option'
A5
B4
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing allocated resources with maximum demand.
Using a value not consistent with the matrix pattern.
2fill in blank
medium

Complete the code to calculate the Need matrix in Banker's algorithm.

Operating Systems
need = [[max_resources[i][j] - [1][i][j] for j in range(m)] for i in range(n)]
Drag options to blanks, or click blank then click option'
Arequest
Ballocation
Cavailable
Dmax_resources
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting available resources instead of allocated.
Using the wrong matrix for calculation.
3fill in blank
hard

Fix the error in the safety check condition to verify if a process can be safely allocated resources.

Operating Systems
if all(need[i][j] <= [1][j] for j in range(m)):
Drag options to blanks, or click blank then click option'
Aallocation
Brequest
Cmax_resources
Davailable
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing Need with Allocation or Max resources.
Using the request matrix incorrectly.
4fill in blank
hard

Fill both blanks to update the Available resources and Allocation matrix after granting a request.

Operating Systems
available = [available[j] - [1][j] for j in range(m)]
allocation[process_id] = [allocation[process_id][j] + [2][j] for j in range(m)]
Drag options to blanks, or click blank then click option'
Arequest
Ballocation
Cavailable
Dneed
Attempts:
3 left
💡 Hint
Common Mistakes
Using Allocation or Need instead of Request for updates.
Updating Available incorrectly.
5fill in blank
hard

Fill all three blanks to check if the system is in a safe state after resource allocation.

Operating Systems
finish = [False] * n
work = available.copy()
for i in range(n):
    if not finish[i] and all(need[i][j] <= [1][j] for j in range(m)):
        work = [work[j] + [2][i][j] for j in range(m)]
        finish[i] = [3]
Drag options to blanks, or click blank then click option'
Awork
Ballocation
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using Available instead of Work in the condition.
Marking finish as False instead of True.
Updating Work incorrectly.