您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 操作系统 实验一 CPU调度
1实验一CPU调度一、实验内容选择一个调度算法,实现处理机调度。二、实验目的多道系统中,当就绪进程数大于处理机数时,须按照某种策略决定哪些进程优先占用处理机。本实验模拟实现处理机调度,以加深了解处理机调度的工作。三、实验题目1、设计一个按优先权调度算法实现处理机调度的程序;2、设计按时间片轮转实现处理机调度的程序。四、实验要求PCB内容:进程名/PID;要求运行时间(单位时间);优先权;状态:PCB指针;21、可随机输入若干进程,并按优先权排序;2、从就绪队首选进程运行:优先权-1/要求运行时间-1要求运行时间=0时,撤销该进程3、重新排序,进行下轮调度;4、最好采用图形界面;5、可随时增加进程;6、规定道数,设置后备队列和挂起状态。若内存中进程少于规定道数,可自动从后备队列调度一作业进入。被挂起进程入挂起队列,设置解挂功能用于将指定挂起进程解挂入就绪队列。7、每次调度后,显示各进程状态。五、实验源码/***@(#)CPUScheduling.java***@authorLiangJiabin*@version1.002010/11/5*/3importjava.awt.*;importjavax.swing.*;importjava.awt.event.ActionListener;importjava.awt.event.ActionEvent;importjava.util.Vector;publicclassCPUSchedulingextendsThread{privateJFrameframe;privateJScrollPanereserveSp,waitingSp,finishSp;privateJListreserveList,readyList,waitingList,finishList;privateDefaultListModelreserveLm,readyLm,waitingLm,finishLm;privateJLabelreserveLbl,readyLbl,CPULbl,waitingLbl,finishLbl;privateJTextFieldCPUTf;privateJLabelneedTimeLbl,priorityLbl;privateJComboBoxneedTimeCb,priorityCb;privateJButtonnewBtn,suspendBtn,unsuspendBtn,exitBtn;privateJLabelrToRLbl,rToCPULbl,CPUToRLbl,CPUToWLbl,wToRLbl;privateJLabelCPUToFLbl,warningLbl,explainLbl;4privateintnumber=1;//进程名序号privateStringCPUProcess=;privateStringCPUProcessId=;privateStringCPUProcessPriority=0;privateStringCPUProcessTime=0;privateStringmaxPriorityProcess=;privateStringmaxPriorityProcessId=;privateStringmaxPriorityProcessTime=;privateStringmaxPriorityProcessPriority=0;privateVectorwaitingReadyV=newVector(1,1);publicCPUScheduling(){frame=newJFrame(CPUScheduling);Containerc=frame.getContentPane();c.setBackground(Color.pink);c.setLayout(null);reserveLbl=newJLabel(后备队列);5reserveLbl.setBounds(50,20,60,30);c.add(reserveLbl);reserveLm=newDefaultListModel();reserveList=newJList(reserveLm);reserveSp=newJScrollPane(reserveList);reserveSp.setBounds(30,50,100,200);c.add(reserveSp);rToRLbl=newJLabel();rToRLbl.setBounds(145,100,60,30);c.add(rToRLbl);readyLbl=newJLabel(就绪队列);readyLbl.setBounds(220,20,60,30);c.add(readyLbl);readyLm=newDefaultListModel();readyList=newJList(readyLm);readyList.setFixedCellHeight(30);readyList.setBounds(200,50,100,200);6c.add(readyList);rToCPULbl=newJLabel();rToCPULbl.setBounds(320,50,50,30);c.add(rToCPULbl);CPUToRLbl=newJLabel();CPUToRLbl.setBounds(320,65,50,30);c.add(CPUToRLbl);CPULbl=newJLabel(CPU);CPULbl.setBounds(410,20,50,30);c.add(CPULbl);CPUTf=newJTextField(20);CPUTf.setEditable(false);CPUTf.setBounds(370,55,100,30);c.add(CPUTf);CPUToWLbl=newJLabel(||);CPUToWLbl.setBounds(415,80,20,50);c.add(CPUToWLbl);7wToRLbl=newJLabel();wToRLbl.setBounds(320,160,50,30);c.add(wToRLbl);waitingLbl=newJLabel(挂起队列);waitingLbl.setBounds(390,110,60,30);c.add(waitingLbl);waitingLm=newDefaultListModel();waitingList=newJList(waitingLm);waitingSp=newJScrollPane(waitingList);waitingSp.setBounds(370,140,100,200);c.add(waitingSp);CPUToFLbl=newJLabel();CPUToFLbl.setBounds(480,55,50,30);c.add(CPUToFLbl);finishLbl=newJLabel(完成队列);finishLbl.setBounds(560,20,60,30);8c.add(finishLbl);finishLm=newDefaultListModel();finishList=newJList(finishLm);finishSp=newJScrollPane(finishList);finishSp.setBounds(540,50,100,200);c.add(finishSp);needTimeLbl=newJLabel(要求运行时间);needTimeLbl.setBounds(10,330,100,30);c.add(needTimeLbl);String[]time={1,2,3,4,5,6,7,8,9};needTimeCb=newJComboBox(time);needTimeCb.setEditable(true);needTimeCb.setBounds(95,330,60,30);c.add(needTimeCb);priorityLbl=newJLabel(优先权);priorityLbl.setBounds(175,330,50,30);c.add(priorityLbl);9String[]priority={1,2,3,4,5,6,7,8,9};priorityCb=newJComboBox(priority);priorityCb.setBounds(220,330,60,30);c.add(priorityCb);newBtn=newJButton(增加);newBtn.setBounds(120,380,60,30);c.add(newBtn);warningLbl=newJLabel();warningLbl.setForeground(Color.RED);warningLbl.setBounds(360,350,200,30);c.add(warningLbl);suspendBtn=newJButton(挂起);suspendBtn.setBounds(340,380,60,30);c.add(suspendBtn);unsuspendBtn=newJButton(解挂);unsuspendBtn.setBounds(440,380,60,30);c.add(unsuspendBtn);10exitBtn=newJButton(退出);exitBtn.setBounds(560,380,60,30);c.add(exitBtn);explainLbl=newJLabel(注:进程信息表示为“进程名,需要运行时间,优先权”);explainLbl.setBounds(10,420,500,30);c.add(explainLbl);//Button事件注册ButtonListenerbtnListener=newButtonListener();newBtn.addActionListener(btnListener);suspendBtn.addActionListener(btnListener);unsuspendBtn.addActionListener(btnListener);exitBtn.addActionListener(btnListener);//调度器线程开启this.start();frame.setSize(720,520);frame.setVisible(true);11frame.setLocationRelativeTo(null);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}/**开启线程*/publicsynchronizedvoidrun(){try{while(true){//判断waiting队列是否有进程在等待进ready队列while(readyLm.size()4&&waitingReadyV.size()!=0){Strings=waitingReadyV.get(0).toString();readyLm.addElement(s);wToRLbl.setForeground(Color.RED);this.sleep(500);12wToRLbl.setForeground(Color.BLACK);waitingReadyV.remove(0);waitingLm.removeElement(s);}//判断后备队列进程能否进就绪队列while(readyLm.size()4&&!reserveLm.isEmpty()){readyLm.addElement(reserveLm.getElementAt(0));rToRLbl.setForeground(Color.RED);this.sleep(500);rToRLbl.setForeground(Color.
本文标题:操作系统 实验一 CPU调度
链接地址:https://www.777doc.com/doc-3370194 .html