/**
* 默认最后一行为剩余的资源数
*/
public class Os {
private static int resourceNum; // 资源数,A,B,C...
private static boolean flag = false; // 判断有无找到一条安全路径
private static List request= new ArrayList(); //请求的进程资源
private static int index;
//发出请求的进程号
public static void main(String[] args) {
List> process = new ArrayList>(); // 进程
List processState = new ArrayList(); // 记录进程状态,有无跑过
// 读取文件信息
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(new File("process.txt")), "UTF-8"));
String lineTxt = null;
while ((lineTxt = br.readLine()) != null) {
String[] names = lineTxt.split(" ");
List temp = new ArrayList();
for (int i = 1; i < names.length; i++) {
temp.add(Integer.valueOf(names[i]));
}
process.add(temp);
}
br.close();
} catch (Exception e) {
System.err.println("read errors :" + e.getMessage());
}
resourceNum = process.get(0).size() / 2;
needResource(process);
while (true) {
showProcess(process);
List available = process.get(process.size() - 1); // 当前拥有的资源数
System.out.println("available" + available);
System.out.println("输入请求资源的进程数(0-" + (process.size() - 2) + "):");
Scanner in = new Scanner(System.in);
index = in.nextInt();