Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views6 pages

OS Lab 5

The document outlines a lab exercise focused on implementing the Banker's Algorithm to analyze system states for deadlocks and safety in resource allocation among processes. It provides input and output formats, detailing how to simulate a conflict analyzer and determine safe sequences or detect deadlocks. Several test cases are included to illustrate the expected results for different scenarios of resource allocation and requests.

Uploaded by

Vansh Raj Singh
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)
4 views6 pages

OS Lab 5

The document outlines a lab exercise focused on implementing the Banker's Algorithm to analyze system states for deadlocks and safety in resource allocation among processes. It provides input and output formats, detailing how to simulate a conflict analyzer and determine safe sequences or detect deadlocks. Several test cases are included to illustrate the expected results for different scenarios of resource allocation and requests.

Uploaded by

Vansh Raj Singh
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
You are on page 1/ 6

Operating Systems​

Lab 5​ ​ ​ ​ ​ ​ ​ ​
Banker's Algorithm

6th April, 2025

Sunday
QUESTION
A system runs multiple processes that frequently request and release shared resources (e.g.,
CPU cores, memory segments, I/O channels). You are given:

●​ The current Allocation Matrix showing how many units of each resource are currently
allocated to each process.
●​ A Pending Request Matrix, indicating how many more units each process may request to
complete.
●​ A vector of Currently Available Resources.

Your task is to:

1.​ Simulate a conflict analyzer that checks whether the system is in a safe state or a
deadlocked state.
2.​ If the system is safe, output the order in which processes can safely complete. You can
output any valid safe sequence.
3.​ If a deadlock exists, report the processes involved.

Constraints:

●​ Do not use any pre-built deadlock detection libraries or OS-level synchronization


functions.
●​ Do not modify the system’s original state — all simulation must work on a copy of the
system state.
●​ Your solution must work for any number of processes and resources (within reasonable
limits).

Input Format:

●​ First line: 2 integers n and m — number of processes and number of resource types.
●​ Next n lines: each has m integers → Allocation matrix.
●​ Next n lines: each has m integers → Request matrix.
●​ Last line: m integers → Available resource vector.

1
Output:

●​ If no deadlock:​
No deadlock detected.​
Safe sequence: P0 P2 P1 ...​

●​ If deadlock:​
Deadlock detected. ​ ​ ​ ​ ​ ​ ​ ​
Processes involved: P1 P4 ...

Test Case 1:
Input:

53

010

200

302

211

002

000

202

000

100

002

000

2
Output:

No deadlock detected.

Safe sequence: P0 P2 P3 P4 P1

Test Case 2:
Input:

32

10

01

11

10

11

11

00

Output:

Deadlock detected. Processes involved: P0 P1 P2

3
Test Case 3:
Input:

4 2

10

01

11

00

10

11

01

00

00

Output:

Deadlock detected. Processes involved: P0 P1 P2

4
Test Case 4:
Input:

43

010

200

302

211

102

000

200

000

112

Output:

No deadlock detected.

Safe sequence: P0 P1 P2 P3

You might also like