THINK FIRST·CODE LATER

← All labs

Deadlock detection with multiple instances

Problem

Implement the detection algorithm.

Input: n m; Available; n rows of Allocation; n rows of Request (current outstanding requests).

  • Processes whose allocation is all zeros are finished from the start (they do not appear in the completion list).
  • Repeat passes over P0…Pn−1: take, in index order, every unfinished process whose Request ≤ Work, and add its Allocation to Work.

Print Can complete (in order): P0 P2 P3 P4 P1 (or none), then No deadlock or DEADLOCK: P1 P2 P3 P4 (the unfinished processes, in index order).

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os8-2-data-1.txt

5 3
0 0 0
0 1 0
2 0 0
3 0 3
2 1 1
0 0 2
0 0 0
2 0 2
0 0 0
1 0 0
0 0 2
What your program must print for os8-2-data-1.txt
Can complete (in order): P0 P2 P3 P4 P1
No deadlock

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os8-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os8-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.