// 进程的终止 public void destroy(int pcb_num, Free _free, Execute _execute, Label[] label_storage, Storage _storage, CPU _cpu) { // 将结果写入out文件 // 回收主存 _storage.recovery(pcb_num, _free, _execute, label_storage, _storage); // 回收进程控制块; _cpu.fromExecuteToFree(_execute, _free); }
// 进程管理函数 #region 创建进程Create // 创建进程 public void create(Free _free, Ready _ready, Label[] label_storage, Storage _storage, CPU _cpu, string instructions) // 创建进程时输入指令 { // 申请空白进程控制块,得到空闲PCB的内部标识符 int pcb_num = _cpu.getPcbFromFreequeue(_free, _cpu); if (pcb_num == 0) { MessageBox.Show("无可用空闲PCB块", "创建进程失败", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } else { // 主存申请,程序装入模拟主存 _storage.allocate(pcb_num, instructions, _storage, label_storage); // 更改进程状态为ready _cpu.tempPCB.state = ProcessState.ready; // 将进程链入就绪队列 // 如果是第一个 if (_ready.num == 0) { _ready.PCBqueue[_ready.num] = _cpu.tempPCB; // 创建进程时,将所有指令存在instructions字符串中 _ready.PCBqueue[_ready.num].instructions = instructions; _ready.num++; } else if (_ready.num >= 1 && _ready.num < 8) { _ready.PCBqueue[_ready.num] = _cpu.tempPCB; // 创建进程时,将所有指令存在instructions字符串中 _ready.PCBqueue[_ready.num].instructions = instructions; // 修改next,使头尾相接,成环形链 //_ready.PCBqueue[_ready.num - 1].next = _ready.num; //_ready.PCBqueue[_ready.num].next = 0; _ready.num++; } else { MessageBox.Show(_ready.num.ToString(), "创建进程失败", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } } }