目录
1 基本信息
l 项目名称: 模拟进程调度管理系统
l 完成人姓名:
l 学号:
l 完成日期: 2017年5月20日
2 实验内容与目的
2.1 实验内容:
编写程序完成单处理器系统的进程调度,要求采用基于时间片多队列反馈式调度策略调度策略。具体内容:
l 确定PCB内容及其组织方式。
l 要求模拟进程空闲(新)、就绪、运行、阻塞和完成5个状态。
l 实现进程创建、进程调度、进程阻塞、进程唤醒和进程撤销5个原语。
l 能够模拟进程从生到灭的完整过程。
2.2 实验目的
l 加深进程概念理解,明确进程与程序区别。
l 理解操作系统中进程的组织、创建和调度等方法。
3 主要设计思路和流程图
3.1 算法流程图
图1 多级反馈队列调度算法流程图
3.2 系统设计架构
图2 系统设计包图
3.3 主要UI设计
3.3.1 就绪队列参数配置
图3 就绪参数配置
3.3.2 输入参数及容错提示
图4 输入进程及容错提示
4 主要数据结构及其说明
4
.1 PCB
图5 PCB类图
4.2 ProQueueBase
ProQueueBase 是封装好的队列,NewQueue(新建队列)、ReadyQueue(就绪队列)、BlockQueue(挂起队列)都继承了它。
图6 队列基类类图
5 程序运行时的初值和运行结果
5.1 系统随机生成初值测试
图7 系统随机生成进程
图8 系统随机生成测试结果
总运行时间:36
5.2 手动输入测试
图9 手动输入进程
图10 手动输入进程挂起展示
图11 手动输入测试结果
总运行时间:57
5.3 文件输入测试
文件输入中,数据格式为:进程名、优先级、总需时间、是否发送挂起、到达时间
图12 文件输入数据
图13 文件输入进程
图14 文件输入测试结果
总运行时间:103
附录
由于源码较多只放了重要代码
/src/business/ ScheduProcessByMF
packagebusiness;
importjava.2awt.event.Mo3useEvent;
im4portjava.awt.event.MouseListener;
importjava.util.Queue;
importjavax.swing.JTable;
importorg.omg.CORBA.PRIVATE_MEMBER;
importdata.BlockQueue;
importdata.NewQueue;
importdata.PCB;
importdata.ReadyQueue;
publicclass ScheduProcessByMF extends Thread{
private ReadyQueue[] readyQueue; //多就绪队列
private NewQueue newQueue; //新建队列
private BlockQueue blockQueue; //挂起队列
private JTable statusTable; //进程显示条
private int SYS_TIME; //模拟系统时
private int current_i; // 当前就绪队列
PCB pcb_run_tp = null; // 就绪队列中的进程临时变量
public boolean exit =false; //用户线程管理
public ScheduProcessByMF(JTablestatusTable,ReadyQueue[] readyQueue,NewQueue newQueue) {
// TODO Auto-generatedconstructor stub
this.readyQueue = readyQueue;
this.statusTable =statusTable;
this.newQueue = newQueue;
this.blockQueue = new BlockQueue(30);
System.out.println("gouzao....."+newQueue.getSize()+"/"+newQueue.getCap());
}
@Override
public void run() {
while(!exit)
{
SYS_TIME = 0; // 系统时初始化
// PCB pcb_new_tp = null; // 新建队列中的进程临时变量
PCBpcb_ready_tp = null; // 就绪队列中的进程临时变量
inttime_round = -1; // 时间片
booleanhasFinished = false; // 进程是否执行完
// boolean hasweak = false; // 进程是否唤醒
while (true){
try { // 模拟系统运行1S
Thread.sleep(1000);
}catch (InterruptedException ex) {
System.out
.println("InterruptedExceptionin ProgressBarThread");
}
SYS_TIME++; //系统时+1
System.out.println("SYS_TIME....."+SYS_TIME);
/**
* new -> ready
*/
NewQueueToReadyQueue(); // 加入就绪队列
/**
* ready->run
*/
if(pcb_run_tp==null) // 如果当前运行的进程为空
{
pcb_run_tp = getNextPCB(); // 获取下一个要执行的进程
// System.out.println("获取下一个要执行的进程....."+pcb_run_tp.getName());
if(pcb_run_tp!=null)
{
time_round = getTimeRound(pcb_run_tp); // 获取时间片大小
statusTable.setValueAt("运行",pcb_run_tp.local , 1);
hasFinished = false;
&nb