-->
当前位置:首页 > 题库

PROGRAMMING:Banker's algorithm -- security check

Luz5年前 (2021-05-10)题库426
Input n processes (n < = 100), and M resources (m < = 100), initialize the total number of various resources, and the allocation of resources at t0. Judge whether t0 is safe or not. For example:
Suppose there are five processes {P 0, p 1, P 2, P 3, P 4} and three types of resources {a, B, C} in the system. The number of resources is 10, 5, 7 respectively. The resource allocation diagram at t0 is as follows:
![ Capture. PNG] (~ / bc6bc36c-f5f8-4c51-bd45-046bc300b262. PNG)
###Input format:
In the first line, enter the number of processes n, in the second line, enter the number of resource classes m, in the third line, enter the total number of resource classes M. in the following N lines, enter the name of each process, the maximum demand of the process for M resources, and the allocated resources.
###Output format:
Output the state of the system at t0. If it is safe, output "find safe sequence, in safe state." Otherwise, the output "no secure sequence found, in an unsafe state."
###Input example:
Here is a set of inputs. For example:
```in
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 2 0 0
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
```
###Output example:
The corresponding output is given here. For example:
```out
name max allocation need available
P0 7 5 3 | 0 1 0 | 7 4 3 | 3 3 2
P1 3 2 2 | 2 0 0 | 1 2 2 |
P2 9 0 2 | 3 0 2 | 6 0 0 |
P3 2 2 2 | 2 1 1 | 0 1 1 |
P4 4 3 2 | 0 0 2 | 4 3 0 |
Safe sequence found, in safe state.
```







answer:If there is no answer, please comment