PROGRAMMING:Banker's algorithm -- Synthesis
Input n processes (n < = 100), and M resources (m < = 100), initialize the total number of various resources, and the allocation of resources at t0. 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:
![ QQ browser screenshot 20201108222915. PNG] (~ / a57b2aa4-9ab4-4277-be4c-a22eb9d77fc6. PNG)
Select the appropriate operation according to the menu:
1. Initialization: enter the number of processes n in the first line, the number of resource classes m in the second line, and the total number of M-class resources in the third line. Enter the name of each process, the maximum demand of the process for M-class resources, and the allocated resources in the following N lines.
2. Security check: judge whether the current system is in a safe state. If it is safe, output "find a safe sequence, in a safe state." Otherwise, the output "no secure sequence found, in an unsafe state."
3. Apply for resources: enter the name of the application process and the number of resources.
If assigned, output "can find the safe sequence, which can be assigned“ If not, give the reasons for not distributing:
(1) If the name of the input process is incorrect, output "no such process found."
(2) If the number of resources applied is greater than the maximum demand, output "unreasonable demand, no allocation."
(3) If the number of resources applied is greater than the remaining resources, output "insufficient remaining resources, no allocation."
(4) If the security sequence cannot be found, output "security sequence not found, not assigned."
4. Current resource allocation: output the current resource allocation according to the format, including process name, maximum demand, obtained resources and available resource vector. For example, at T0, the current resource allocation is as follows:
![ QQ browser screenshot 20201109193605. PNG] (~ / d1f69481-38ad-45a9-a17b-6ec8c7591251. PNG)
0. Exit
Other: output "input error, please input again."
###Input format:
First display the menu (only once), and then select according to the requirements:
![ QQ browser screenshot 20201109202544. PNG] (~ / 11ab4cec-c1cd-4039-971d-3d3734587284. PNG)
Select the corresponding operation according to the label.
###Output format:
According to the selection, output the corresponding data.
###Input sample 1:
Here is a set of inputs. For example:
```in
one
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
two
0
```
###Output sample 1:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Safe sequence found, in safe state.
```
###Input sample 2:
Here is a set of inputs. For example:
```in
one
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
two
four
0
```
###Output sample 2:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Safe sequence found, in safe state.
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 |
```
###Input sample 3:
Here is a set of inputs. For example:
```in
one
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
three
P1 1 0 2
0
```
###Output sample 3:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Secure sequences can be found and assigned.
```
###Input sample 4:
Here is a set of inputs. For example:
```in
one
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
three
P6 1 0 2
0
```
###Output sample 4:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
There is no such process.
```
###Input sample 5:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
three
P4 3 3 0
0
```
###Output sample 5:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
The remaining resources are insufficient and shall not be allocated.
```
###Input sample 6:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
three
P0 0 2 0
0
```
###Output sample 6:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Security sequence not found, not assigned.
```
###Input sample 7:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
three
P1 2 2 0
0
```
###Output sample 7:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Unreasonable demand, no distribution.
```
###Input sample 8:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
nine
0
```
###Output sample 8:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Input error, please input again!
```
answer:If there is no answer, please comment
![ QQ browser screenshot 20201108222915. PNG] (~ / a57b2aa4-9ab4-4277-be4c-a22eb9d77fc6. PNG)
Select the appropriate operation according to the menu:
1. Initialization: enter the number of processes n in the first line, the number of resource classes m in the second line, and the total number of M-class resources in the third line. Enter the name of each process, the maximum demand of the process for M-class resources, and the allocated resources in the following N lines.
2. Security check: judge whether the current system is in a safe state. If it is safe, output "find a safe sequence, in a safe state." Otherwise, the output "no secure sequence found, in an unsafe state."
3. Apply for resources: enter the name of the application process and the number of resources.
If assigned, output "can find the safe sequence, which can be assigned“ If not, give the reasons for not distributing:
(1) If the name of the input process is incorrect, output "no such process found."
(2) If the number of resources applied is greater than the maximum demand, output "unreasonable demand, no allocation."
(3) If the number of resources applied is greater than the remaining resources, output "insufficient remaining resources, no allocation."
(4) If the security sequence cannot be found, output "security sequence not found, not assigned."
4. Current resource allocation: output the current resource allocation according to the format, including process name, maximum demand, obtained resources and available resource vector. For example, at T0, the current resource allocation is as follows:
![ QQ browser screenshot 20201109193605. PNG] (~ / d1f69481-38ad-45a9-a17b-6ec8c7591251. PNG)
0. Exit
Other: output "input error, please input again."
###Input format:
First display the menu (only once), and then select according to the requirements:
![ QQ browser screenshot 20201109202544. PNG] (~ / 11ab4cec-c1cd-4039-971d-3d3734587284. PNG)
Select the corresponding operation according to the label.
###Output format:
According to the selection, output the corresponding data.
###Input sample 1:
Here is a set of inputs. For example:
```in
one
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
two
0
```
###Output sample 1:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Safe sequence found, in safe state.
```
###Input sample 2:
Here is a set of inputs. For example:
```in
one
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
two
four
0
```
###Output sample 2:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Safe sequence found, in safe state.
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 |
```
###Input sample 3:
Here is a set of inputs. For example:
```in
one
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
three
P1 1 0 2
0
```
###Output sample 3:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Secure sequences can be found and assigned.
```
###Input sample 4:
Here is a set of inputs. For example:
```in
one
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
three
P6 1 0 2
0
```
###Output sample 4:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
There is no such process.
```
###Input sample 5:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
three
P4 3 3 0
0
```
###Output sample 5:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
The remaining resources are insufficient and shall not be allocated.
```
###Input sample 6:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
three
P0 0 2 0
0
```
###Output sample 6:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Security sequence not found, not assigned.
```
###Input sample 7:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
three
P1 2 2 0
0
```
###Output sample 7:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Unreasonable demand, no distribution.
```
###Input sample 8:
Here is a set of inputs. For example:
```in
one
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 3 0 2
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
nine
0
```
###Output sample 8:
The corresponding output is given here. For example:
```out
***
1. Initialization
2. Safety inspection
3. Request resources
4. Current resource allocation
0. Exit
***
Please select:
Input error, please input again!
```
answer:If there is no answer, please comment