/// <summary> /// Third part of multi_level_feedback_queue /// </summary> void process_finished() { pcb_contents pc = PCB[running_id]; pc.status = "finished"; PCB[running_id] = pc; }
/// <summary> /// Change the state /// </summary> /// <param name="id"></param> /// <param name="current_state"></param> void state_switching(int id, string current_state) { pcb_contents pc = PCB[id]; pc.status = current_state; PCB[id] = pc; }
/** * FOURTH * PRINT * */ /// <summary> /// First print /// </summary> /// <param name="left_process_id">Prevoius process id</param> /// <param name="current_process_id"></param> /// <param name="slice_times">The times of time_slice</param> /// void print_process_scheduling(int left_process_id, int current_process_id, int slice_times) { pcb_contents current_pcb = PCB[current_process_id]; pcb_contents left_pcb = PCB[current_process_id]; textBox2.AppendText(System.Environment.NewLine + System.Environment.NewLine + "The Process ‘" + current_process_id + "’ is running in time - slice " + slice_times + "’”" + System.Environment.NewLine + System.Environment.NewLine); textBox2.AppendText("PCB" + System.Environment.NewLine); textBox2.AppendText("Current Process ID:" + current_process_id + System.Environment.NewLine + "Status:" + PCB[current_process_id].status + System.Environment.NewLine + "Priority:" + PCB[current_process_id].priority + System.Environment.NewLine + "Runtime:" + current_pcb.runtime + System.Environment.NewLine + "IO time: " + current_pcb.io_time + System.Environment.NewLine + "IO duration:" + current_pcb.io_duration + System.Environment.NewLine + "IO type:" + current_pcb.io_type + System.Environment.NewLine + System.Environment.NewLine); if (left_process_id == -1) { textBox2.AppendText("Previous Process: []"); } else { textBox2.AppendText("Previous Process ID:" + left_process_id + System.Environment.NewLine + "Status:" + PCB[left_process_id].status + System.Environment.NewLine + "Priority:" + PCB[left_process_id].priority + System.Environment.NewLine + "Runtime:" + left_pcb.runtime + System.Environment.NewLine + "IO time: " + left_pcb.io_time + System.Environment.NewLine + "IO duration:" + left_pcb.io_duration + System.Environment.NewLine + "IO type:" + left_pcb.io_type + System.Environment.NewLine + System.Environment.NewLine); } //写文件 write_print_txt(); }
/// <summary> /// One loop is one Scheduling, and it's one time_slice, /// In other part of the loop, make the process state switch. /// </summary> void multi_level_feedback_queue() { double current_time_slice; int finished_number = 0; while (finished_number < PCB.Count) { int previous_id = running_id; //jishu slice_times++; current_time_slice = process_schedule(previous_id); //new code if (three_time[running_id].cpu_time1 > 0) { double time1 = three_time[running_id].cpu_time1 - current_time_slice; if (time1 > 0) { ready_queue_2.Enqueue(running_id); pcb_contents pc = PCB[running_id]; pc.priority = 2; PCB[running_id] = pc; three_times tt1 = three_time[running_id]; tt1.cpu_time1 = time1; three_time[running_id] = tt1; // state_switching(running_id, "ready"); textBox2.AppendText(System.Environment.NewLine + "====RUNNING TO READY=====" + System.Environment.NewLine); print_state_switching(); } // Block else if (time1 <= 0 && three_time[running_id].io_time > 0) { current_time_slice += time1; // update three_times tt1 = three_time[running_id]; tt1.cpu_time1 = 0; three_time[running_id] = tt1; if (PCB[running_id].io_type == "Black and white print") { print_queue.Enqueue(running_id); } else { color_printing_queue.Enqueue(running_id); } // state_switching(running_id, "block"); textBox2.AppendText(System.Environment.NewLine + "====RUNNING TO BLOCK=====" + System.Environment.NewLine); print_state_switching(); } // finshed else { current_time_slice += time1; process_finished(); finished_number++; // state_switching(running_id, "finished"); textBox2.AppendText(System.Environment.NewLine + "====FINISHED=====" + System.Environment.NewLine); print_state_switching(); } } else { double time1 = three_time[running_id].cpu_time2 - current_time_slice; // priority -= 1 if (time1 > 0) { ready_queue_2.Enqueue(running_id); pcb_contents pc = PCB[running_id]; pc.priority = 2; PCB[running_id] = pc; three_times tt1 = three_time[running_id]; tt1.cpu_time1 = time1; three_time[running_id] = tt1; // state_switching(running_id, "ready"); textBox2.AppendText(System.Environment.NewLine + "====RUNNING TO READY=====" + System.Environment.NewLine); print_state_switching(); } // finshed else { current_time_slice += time1; process_finished(); finished_number++; // state_switching(running_id, "finshed"); textBox2.AppendText(System.Environment.NewLine + "====FINISHED=====" + System.Environment.NewLine); print_state_switching(); } } // Run the IO all_process_block_wakeup(current_time_slice); } // Process revocation process_delete(); }