版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
操作系统课程设计班级:计科4班组员:实验名称CPU进程调度和内存分配实验内容一、选择一个调度算法,实现处理机调度二、处理机调度过程中,主存储器空间的分配和回收实验目的加深对CPU进程调度和内存分配的了解,进一步了解操作系统中各功能的实现,了解在不同的存储管理方式下,应怎样实现主存空间的分配和回收。实验内容一、(1)设计一个按照优先权调度算法实现处理机调度的程序(2)设计按时间片轮转实现处理机调度的程序二、在可变分区管理方式下,采用最先适应算法实现主存空间的分配和回收;实验过程及分析1.原理知识:(1)作业进入内存中,由CPU分配产生PCB属性,并通过PCB记录进程状态,实验即以PCB代表进程模拟调度过程;(2)在多道系统中,当就绪进程数大于处理机数时,须按照某种策略决定哪些进程优先占用处理机,本设计采用优先级;(3)进程调度时,规定若就绪队列进程数少于6个,则自动从后备队列调入一个作业;(4)系统会将占有较多资源、预期结果不符合要求的进程自动挂起,并回收所占资源,而本实验设置为手动挂起;(5)在适宜条件下,系统会将挂起的进程自动解挂,而且只解挂到就绪队列;本设计为简化操作,设置为手动解挂,若解挂条件合适(即CPU各种资源可用),则解挂到就绪队列,并分配内存;若解挂条件不适宜,则解挂至后备队列,但不分配内存;2、实验程序设计:(1)本实验采用java语言编程,并实现界面显示。(2)为体现java语言面对对象程序设计的特点,实验设计为ProcessPCB、MemoryItem类封装PCB和所分配的内存各自的属性与方法;用ProcessRecords、MemoryRecords类封装数组方法;用SingleCPUScheduling实现GUI界面显示;(3)ProcessPCB类中,定义PCB的进程名、要求运行时间、优先级、状态、主存起始位置、所需内存大小这6个属性,并定义各属性的get和set方法,定义equals方法用于对比类的属性,定义toString方法得到类属性的字符串,定义run方法封装优先权-1/要求运行时间-1的过程;MemoryItem类中,定义可分分区表每一可分记录的主存起始位置、内存大小及其get和set方法,定义toString方法得到可在界面显示的字符串;(4)ProcessRecords封装PCB数组的添加元素addItem和删除元素removeItem方法,并构造函数getItem通过参数ProcessPCB和String查找数组元素,定义getNumberOfItems取数组大小,定义getItemsPriorities方法取所有数组元素的toString方法用于界面显示,定义iterator方法取得数组的迭代器;(5)MemoryRecords用同样的设计思想封装以MemoryItem为数组元素的各属性和方法;(6)SingleCPUScheduling类继承JFrame类,实现界面化显示;与上面相对应,实例化ProcessRecords(3次)和MemoryRecords(1次)作为私有变量,分别作为后备队列、就绪队列、挂起队列和内存可分分区表;在界面设计中,设计后备队列、挂起队列(附带解挂umount按钮)、就绪队列(附带挂起suspend按钮)可分分区表列表显示框,设置PCB添加框,附带添加至后备队列(addToBackup)、添加至就绪队列(addToReady)按钮,以及CPU当前执行状态显示框、系统日志显示框,和开始调度(systemStart)按钮,优先级和时间片单选按钮,以及时间片显示标签和文本编辑框;(7)界面设计详解;后备队列显示框用于显示已添加至后备队列的ProcessRecords属性信息,其中主存起始位置默认为-1,表示未分配;挂起队列显示框用于显示从就绪队列挂起的PCB,其中属性“主存起始位置”(MemoryBase)将由非负数变为-1,表示挂起后收回内存;就绪队列显示框中显示就绪队列属性,其中“主存起始位置”均为非负,表示一分配内存;PCB信息添加框分列PCB6个属性显示标签和可编辑文本框,和添加按钮,用于添加PCB;系统日志显示框附属时间片显示标签和可编辑文本编辑框,可由用户决定时间片大小;(8)附属功能添加完善;最重要的是为程序添加线程,是程序能以停顿一段时间的频率自动运行;后备队列、挂起队列添加total显示标签和不可编辑文本显示框,用于显示各自数组中元素数目,挂起队列附属删除(remove)按钮,可删除挂起队列中的元素;后备、挂起、就绪队列均添加监听器,用于响应用户单击操作,可以在PCB信息添加框显示用户单击的那一条PCB的信息;PCB信息添加框附属reset按钮,用于一键清空信息框中信息,方便输入;系统日志面板附属系统暂停(systemPause)和系统重置(systemReset)按钮,分别用于暂停运行(方便用户观察当前运行结果)和重置系统(方便用户重复使用程序,免去关闭后重启本程序的麻烦);最终界面如图:设计结果报告和分析本程序还存在一些技术上的问题,使得程序不能尽善尽美;如,PCB信息添加框没有“随机置入就绪队列”功能,添加PCB信息仍显得繁琐;就绪队列的挂起功能在程序自动运行时,存在反应异常(反应延迟或直接无反映);可分分区表只显示了当前可分的内存,没有显示已分的PCB及其对应内存使用情况,且没有利用图形和丰富的颜色来更好的展示;时间片设计还需要改进,使用效率不高;系统重置功能存在响应延迟的问题;另外,界面不够美观;还需要不断改进。设计感想通过这次实验,我们对操作系统的进程调度和内存分配管理有了更加深入的了解,对操作系统内部的工作原理有了进一步的认识。通过编程,也巩固了我们的程序设计和代码编写的能力,实验过程中遇到的各种问题以及解决问题的过程与方法,都是我们获益匪浅。同时,程序的不完善,也将促使我们在课程之后,继续学习、理解课程内容,并尽一切努力不断完善程序,做到尽善尽美。程序代码:packagesrc;publicclassMemoryItem{ privateintmemoryBase=0; privateintmemoryLimit=0; privateintavailableStatus=0; publicMemoryItem(intinitMemoryBase,intinitMemoryLimit){ this.memoryBase=initMemoryBase; this.memoryLimit=initMemoryLimit; } publicintgetMemoryBase(){ returnthis.memoryBase; }publicintgetMemoryLimit(){ returnthis.memoryLimit; }publicintgetStatus(){ returnthis.availableStatus; }publicStringtoString(){ returnthis.getMemoryBase()+"_"+this.getMemoryLimit()+"\n";}}packagesrc;publicclassProcessPCB{// backupBAK后备ready就绪suspend挂起memory内存 privateStringPID; privateintRequiredTime; privateintPriority; privateStringStatus; privateintMwmoryBase=0000; privateintMemoryLimit;// privateStringPCBPointer; publicProcessPCB(StringinitpID,intinitRTime,intinitpriority, Stringstatus,intinitBase,intinitLimit){ this.PID=initpID; this.RequiredTime=initRTime; this.Priority=initpriority; this.Status=status; this.MwmoryBase=initBase; this.MemoryLimit=initLimit; } publicStringgetPID(){ if(this.PID==null) return""; else returnthis.PID; } publicintgetRequiredTime(){ returnthis.RequiredTime; } publicintgetPriority(){ returnthis.Priority; } publicStringgetStatus(){ if(this.Status==null) return""; else returnthis.Status; } publicintgetMemoryBase(){ returnthis.MwmoryBase; } publicintgetMemoryLimit(){ returnthis.MemoryLimit; } publicbooleanequals(ProcessPCBpcb){ if(pcb.getPID()==this.getPID()){ returntrue; } elsereturnfalse; } publicStringtoString(){ returnthis.getPID()+"_"+this.getRequiredTime()+"_"+this.getPriority()+"_" +this.getStatus()+"_"+this.getMemoryBase()+"_"+this.getMemoryLimit()+"\n"; } publicvoidrun(){ this.RequiredTime=this.RequiredTime-1; this.Priority=this.Priority-1; } }packagesrc;importjava.util.ArrayList;importjava.util.Iterator;publicclassPCBRecordsimplementsIterable<ProcessPCB>{ privateArrayList<ProcessPCB>PCBItems; publicArrayList<ProcessPCB>getPCBItems(){ returnthis.PCBItems; }publicPCBRecords(){ this.PCBItems=newArrayList<ProcessPCB>(); }publicvoidaddItem(ProcessPCBPcbItem){ this.PCBItems.add(PcbItem); }publicvoidremoveItem(ProcessPCBPCbItem){ this.PCBItems.remove(PCbItem); }publicProcessPCBgetItem(ProcessPCBprocessPCB){ for(ProcessPCBpCbItem:this.PCBItems){ if(pCbItem.equals(processPCB)){ returnpCbItem; } } returnnull; } publicProcessPCBgetItem(Stringpid){ for(ProcessPCBpcBItem:this.PCBItems){ if(pcBItem.getPID().equals(pid)){ returnpcBItem; } } returnnull; }publicintgetNumberOfItems(){ returnthis.PCBItems.size(); }publicString[]getItemsProperties(){ StringitemsProperties[]=newString[getNumberOfItems()]; inti=0;for(Iteratoriterator1=PCBItems.iterator();iterator1.hasNext();){ ProcessPCBstu_Item=(ProcessPCB)iterator1.next(); itemsProperties[i++]=stu_Item.toString();}returnitemsProperties; } publicIterator<ProcessPCB>iterator(){ returnthis.PCBItems.iterator(); }}packagesrc;importjava.util.ArrayList;importjava.util.Iterator;publicclassMemoryRecordsimplementsIterable<MemoryItem>{ privateArrayList<MemoryItem>memoryItems; publicIterator<MemoryItem>iterator(){ //TODOAuto-generatedmethodstub returnthis.memoryItems.iterator(); }publicArrayList<MemoryItem>getMemoryItems(){ returnthis.memoryItems; }publicMemoryRecords(){ this.memoryItems=newArrayList<MemoryItem>();}publicvoidaddItem(MemoryItemnewMemoryItem){ this.memoryItems.add(newMemoryItem);}publicvoidremoveItem(MemoryItemmomoryItem){ this.memoryItems.remove(momoryItem);}publicMemoryItemgetMomoryItem(MemoryItemitem){ for(MemoryItemmItem:this.memoryItems){ if(mItem.equals(item)){ returnmItem; } } returnnull;}publicMemoryItemgetMemoryItem(intbase){ for(MemoryItemmItem:this.memoryItems){ if(mItem.getMemoryBase()==base){ returnmItem; } } returnnull;}publicintgetNumberOfItems(){ returnthis.memoryItems.size(); }publicString[]getItemsProperties(){ StringitemsProperties[]=newString[getNumberOfItems()]; inti=0; for(Iteratoriterator1=this.memoryItems.iterator();iterator1.hasNext();){ MemoryItemmmItem=(MemoryItem)iterator1.next(); itemsProperties[i++]=mmItem.toString(); } if(itemsProperties==null){ itemsProperties[0]=""; } returnitemsProperties;}}packagesrc;importjava.util.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;importsrc.SingleCPUSchedulingGUI03.AddToBAKListener;importsrc.SingleCPUSchedulingGUI03.AddToReadyListener;importsrc.SingleCPUSchedulingGUI03.DisplayBackupProcessListener;importsrc.SingleCPUSchedulingGUI03.DisplaySuspendedProcessListener;importsrc.SingleCPUSchedulingGUI03.DisplayreadyProcessListener;importsrc.SingleCPUSchedulingGUI03.RemoveListener;importsrc.SingleCPUSchedulingGUI03.ResetListener;importsrc.SingleCPUSchedulingGUI03.ResetSystemListener;importsrc.SingleCPUSchedulingGUI03.StartSystemListener;importsrc.SingleCPUSchedulingGUI03.SuspendListener;importsrc.SingleCPUSchedulingGUI03.UmountListener;//importsrc.myframe.MyWindowMonitor;importjava.io.*;importjava.text.*;publicclassSingleCPUSchedulingGUI03extendsJFrame{ /*Standarerrorstream*/ staticprivatePrintWriterstdErr=newPrintWriter(System.err,true); staticprivateintWIDTH=800,HEIGHT=750;//thesizeoftheFrame主面板 /*各列表对应的面板规格*//* 对应各名词释义backupBAK后备ready就绪suspend挂起memory内存*/ staticprivateintBackupBAK_CELL_SIZE=250,BackupBAK_LIST_ROWS=10; //后备队列 staticprivateintSuspend_CELL_SIZE=250,Suspend_LIST_ROWS=10; //挂起队列 staticprivateintReady_CELL_SIZE=200,Ready_LIST_ROWS=6; //就绪队列 staticprivateintMemory_CELL_SIZE=200,Memory_LIST_ROWS=10;//内存队列 staticprivateintCPU_ROWS=12,CPU_COLS=22;//CPU面板 staticprivateintSTATUS_ROWS=8,STATUS_COLS=30;//系统状态面板privateinttimeslice=1;//设置时间片大小privateintsystemStatus=0;//设置系统状态0——系统预备状态,等待开始,1——系统运行状态,2——系统暂停状态 staticprivateintTOTAL__TEXTFIELD_SIZE=10; //Sizetotaltextfield记录各队列元素个数 privateJListbackupList,suspendList,readyList,memoryList;//各队列相对应的数组列表 privateJButtonaddToBAKButton,addToReadyButton,resetButton;// 进程添加框中的"添加至后备队列","添加至就绪队列","重置"Button privateJButtonsuspendButton,umountButton,removeButton;//就绪队列框中的"挂起",挂起队列框中的"解挂","删除"Button privateJButtonstartButton,pauseButton,resetSyatemButton;//Status面板中的"启动系统","重置系统"Button //优先级和时间片单选钮及时间片显示框 privateJRadioButtonpriorityJRB,timesliceJRB; privateJLabeltimesliceSizeLabel; privateJTextFieldtimesliceJtf; privateJPanelbackupBAKPanel,PCBItemPanel,suspendedPanel,memoryPanel;//后备面板、进程添加面板、挂起面板、内存面板 privateJLabelbackupTotalLabel,suspendTotalLabel;//后备队列、挂起队列元素总数标签 privateJLabelPIDLabel,requiredTimeLabel,priorityLabel,statuesLabel,baseLabel,limitLabel;// 进程信息标签进程编号PID,所需运行时间requiredTime,优先级priority,当前状态statues,内存中的基址base,所需内存大小limit privateJTextFieldbackupTotalTextField,suspendTotalTextField;// 后备队列、挂起队列元素总数文本框(不可编辑) privateJTextFieldPIDTextField,requiredTimeTextField,priorityTextField,statusTextField,baseTextField,limitTextField;//CPU状态显示文本域(不可编辑),status信息文本域(用于现实程序每一步的操作和影响,不可编辑) privateJTextAreaCPUTextArea,statuesTextArea; //后备队列PCB数组,就绪、挂起,——内存(可分分区表) PCBRecordsbackupPCB,readyPCB,suspendedPCB; privateMemoryRecordsmemoryItems; privatebooleanflag=false;//main函数 publicstaticvoidmain(String[]args)throwsIOException{ newSingleCPUSchedulingGUI03().initFrame(); } //初始化Frame publicvoidinitFrame(){ backupList=newJList(); backupList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); backupList.setVisibleRowCount(BackupBAK_LIST_ROWS); backupList.setFixedCellWidth(BackupBAK_CELL_SIZE); suspendList=newJList(); suspendList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); suspendList.setVisibleRowCount(Suspend_LIST_ROWS); suspendList.setFixedCellWidth(Suspend_CELL_SIZE); readyList=newJList(); readyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); readyList.setVisibleRowCount(Ready_LIST_ROWS); readyList.setFixedCellWidth(Ready_CELL_SIZE); memoryList=newJList(); memoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); memoryList.setVisibleRowCount(Memory_LIST_ROWS); memoryList.setFixedCellWidth(Memory_CELL_SIZE); suspendButton=newJButton("挂起"); addToBAKButton=newJButton("添加至后备队列"); addToReadyButton=newJButton("添加至就绪队列"); resetButton=newJButton("重置"); umountButton=newJButton("解挂"); removeButton=newJButton("删除"); startButton=newJButton("开始调度"); pauseButton=newJButton("暂停"); resetSyatemButton=newJButton("重启系统"); priorityJRB=newJRadioButton("优先权",true); timesliceJRB=newJRadioButton("时间片"); backupTotalLabel=newJLabel("总计:"); backupTotalTextField=newJTextField("0",TOTAL__TEXTFIELD_SIZE); backupTotalTextField.setEditable(false); suspendTotalLabel=newJLabel("总计:"); suspendTotalTextField=newJTextField("0",TOTAL__TEXTFIELD_SIZE); suspendTotalTextField.setEditable(false); timesliceSizeLabel=newJLabel("时间片"); timesliceJtf=newJTextField("3",5); timesliceJtf.setEditable(true); CPUTextArea=newJTextArea(CPU_ROWS,CPU_COLS); CPUTextArea.setEditable(false); statuesTextArea=newJTextArea(STATUS_ROWS,STATUS_COLS); statuesTextArea.setEditable(false); /*northpanel*/ JPanelnorthPanel=newJPanel(newGridLayout(1,3)); //ProcessPCBiteminformationPanel PCBItemPanel=newJPanel(newBorderLayout()); PCBItemPanel.setBorder( BorderFactory.createTitledBorder("PCB信息")); JPanelPCBItemButtonJPanel=newJPanel(newGridLayout(3,1)); PCBItemButtonJPanel.add(addToBAKButton); PCBItemButtonJPanel.add(addToReadyButton); PCBItemButtonJPanel.add(resetButton); PCBItemPanel.add(this.initPCBItemPanel(),BorderLayout.CENTER); PCBItemPanel.add(PCBItemButtonJPanel,BorderLayout.SOUTH); //backupBAKListPanel backupBAKPanel=newJPanel(newBorderLayout()); backupBAKPanel.setBorder(BorderFactory.createTitledBorder("后备列表")); JPanelbackupTotalPAnel=newJPanel();backupTotalPAnel.add(backupTotalLabel);backupTotalPAnel.add(backupTotalTextField);backupBAKPanel.add( newJScrollPane(backupList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),BorderLayout.CENTER);backupBAKPanel.add(backupTotalPAnel,BorderLayout.SOUTH);//SuspendListPanelsuspendedPanel=newJPanel(newBorderLayout());suspendedPanel.setBorder(BorderFactory.createTitledBorder("挂起列表"));JPanelsuspendedTotalPAnel=newJPanel();suspendedTotalPAnel.add(suspendTotalLabel);suspendedTotalPAnel.add(suspendTotalTextField);JPanelsuspendComponentPanel=newJPanel(newGridLayout(1,2));suspendComponentPanel.add(umountButton);suspendComponentPanel.add(removeButton);suspendedPanel.add(suspendedTotalPAnel,BorderLayout.NORTH);suspendedPanel.add( newJScrollPane(suspendList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),BorderLayout.CENTER);suspendedPanel.add(suspendComponentPanel,BorderLayout.SOUTH);northPanel.add(backupBAKPanel);northPanel.add(PCBItemPanel);northPanel.add(suspendedPanel);/*centerPanel*/JPanelcentrelPanel=newJPanel(newGridLayout(1,3));//readyListpanelJPanelreadyListPanel=newJPanel(newBorderLayout());readyListPanel.setBorder(BorderFactory.createTitledBorder("就绪列表"));readyListPanel.add( newJScrollPane(readyList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));readyListPanel.add(suspendButton,BorderLayout.SOUTH);//CPUpanelJPanelCPUPanel=newJPanel();CPUPanel.setBorder(BorderFactory.createTitledBorder("CPU"));CPUPanel.add(newJScrollPane(CPUTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));memoryPanel=newJPanel(newBorderLayout());memoryPanel.setBorder(BorderFactory.createTitledBorder("内存列表"));memoryPanel.add( newJScrollPane(memoryList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));centrelPanel.add(readyListPanel);centrelPanel.add(CPUPanel);centrelPanel.add(memoryPanel);/*statuespanel*/JPanelsouthPanel=newJPanel(newBorderLayout());JPanelstatuesPanel=newJPanel();statuesPanel.setBorder(BorderFactory.createTitledBorder("状态"));statuesPanel.add(newJScrollPane(statuesTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));JPanelsystemContralButtonPanel=newJPanel(newGridLayout(6,1));systemContralButtonPanel.setBorder(BorderFactory.createTitledBorder("系统控制"));ButtonGroupgroup=newButtonGroup();group.add(priorityJRB);group.add(timesliceJRB);JPanelporityPanel=newJPanel(newGridLayout(1,2));porityPanel.add(timesliceSizeLabel);porityPanel.add(timesliceJtf);systemContralButtonPanel.add(priorityJRB);systemContralButtonPanel.add(timesliceJRB);systemContralButtonPanel.add(porityPanel);systemContralButtonPanel.add(startButton);systemContralButtonPanel.add(pauseButton);systemContralButtonPanel.add(resetSyatemButton);southPanel.add(statuesPanel,BorderLayout.CENTER);southPanel.add(systemContralButtonPanel,BorderLayout.EAST);// arrangepanelsinwindow setLayout(newBorderLayout()); add(northPanel,BorderLayout.NORTH); add(centrelPanel,BorderLayout.CENTER); add(southPanel,BorderLayout.SOUTH);//statuesPanel // startlisteningforlistandbuttonsevents backupList.addListSelectionListener(newDisplayBackupProcessListener()); suspendList.addListSelectionListener(newDisplaySuspendedProcessListener()); readyList.addListSelectionListener(newDisplayreadyProcessListener()); addToBAKButton.addActionListener(newAddToBAKListener()); addToReadyButton.addActionListener(newAddToReadyListener()); resetButton.addActionListener(newResetListener()); suspendButton.addActionListener(newSuspendListener()); umountButton.addActionListener(newUmountListener()); removeButton.addActionListener(newRemoveListener()); startButton.addActionListener(newStartSystemListener()); pauseButton.addActionListener(newSystemPauseListener()); resetSyatemButton.addActionListener(newResetSystemListener()); priorityJRB.addActionListener(newpriotiryListener()); timesliceJRB.addActionListener(newtimeslicListener()); backupPCB=newPCBRecords(); readyPCB=newPCBRecords(); suspendedPCB=newPCBRecords(); memoryItems=newMemoryRecords(); MemoryIteminitMemoryItem=newMemoryItem(0,3000); memoryItems.addItem(initMemoryItem); backupList.setListData(backupPCB.getItemsProperties()); readyList.setListData(readyPCB.getItemsProperties()); suspendList.setListData(suspendedPCB.getItemsProperties()); memoryList.setListData(memoryItems.getItemsProperties()); this.setTitle("CPU调度"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(WIDTH,HEIGHT); this.setResizable(true); this.setVisible(true); this.setLocation(200,10); this.addWindowListener(newMyWindowMonitor()); } publicJPanelinitPCBItemPanel(){ JPaneliniPCBItemJPanel=newJPanel(newBorderLayout()); JPaneliniNamePanel=newJPanel(newGridLayout(6,1)); JPaneliniValuePanel=newJPanel(newGridLayout(6,1)); PIDLabel=newJLabel("PID:"); requiredTimeLabel=newJLabel("所需时间:"); priorityLabel=newJLabel("优先权:"); statuesLabel=newJLabel("状态:"); baseLabel=newJLabel("基态:"); limitLabel=newJLabel("限制:"); iniNamePanel.add(PIDLabel); iniNamePanel.add(requiredTimeLabel); iniNamePanel.add(priorityLabel); iniNamePanel.add(statuesLabel); iniNamePanel.add(baseLabel); iniNamePanel.add(limitLabel); PIDTextField=newJTextField("",10); PIDTextField.setEditable(true); requiredTimeTextField=newJTextField("",10); requiredTimeTextField.setEditable(true); priorityTextField=newJTextField("",10); priorityTextField.setEditable(true); statusTextField=newJTextField("",10); statusTextField.setEditable(false); baseTextField=newJTextField("",10); baseTextField.setEditable(false); limitTextField=newJTextField("",10); limitTextField.setEditable(true); iniValuePanel.add(PIDTextField); iniValuePanel.add(requiredTimeTextField); iniValuePanel.add(priorityTextField); iniValuePanel.add(statusTextField); iniValuePanel.add(baseTextField); iniValuePanel.add(limitTextField); iniPCBItemJPanel.add(iniNamePanel,BorderLayout.WEST); iniPCBItemJPanel.add(iniValuePanel,BorderLayout.CENTER); returniniPCBItemJPanel; } classMyWindowMonitorextendsWindowAdapter{ publicvoidwindowClosing(WindowEvente){ System.exit(0); setVisible(false); } } publicvoiddisplayInformation(ProcessPCBpcb){ PIDTextField.setText(pcb.getPID()); requiredTimeTextField.setText(Integer.toString(pcb.getRequiredTime())); priorityTextField.setText(Integer.toString(pcb.getPriority())); statusTextField.setText(pcb.getStatus()); baseTextField.setText(Integer.toString(pcb.getMemoryBase())); limitTextField.setText(Integer.toString(pcb.getMemoryLimit())); } //DisplaystheinformationoftheselectedPCBItem classDisplayBackupProcessListenerimplementsListSelectionListener{ publicvoidvalueChanged(ListSelectionEventevent){ if(!backupList.getValueIsAdjusting()){ Stringid=null,selectedBAKItem=null; selectedBAKItem=(String)backupList.getSelectedValue(); if(selectedBAKItem!=null){ StringTokenizerstringtokenizer=newStringTokenizer(selectedBAKItem,"_"); id=stringtokenizer.nextToken(); ProcessPCBbackupItem=backupPCB.getItem(id); if(backupItem!=null) { displayInformation(backupItem); } statuesTextArea.append(backupItem.toString()+"ProcessItem"+id +"inbackupListhasbeendisplayed!\n"); } } } } classDisplaySuspendedProcessListenerimplementsListSelectionListener{ publicvoidvalueChanged(ListSelectionEventevent){ if(!suspendList.getValueIsAdjusting()){// stdErr.flush(); Stringid=""; Stringstr=(String)suspendList.getSelectedValue(); if(str!=null){ StringTokenizerstrtokenizer=newStringTokenizer(str,"_"); id=strtokenizer.nextToken(); ProcessPCBselectedSuspendedItem=suspendedPCB.getItem(id); if(selectedSuspendedItem!=null) { displayInformation(selectedSuspendedItem); } statuesTextArea.append(selectedSuspendedItem.toString()+"ProcessItem"+id +"insuspendListhasbeendisplayed!\n"); } } } } classDisplayreadyProcessListenerimplementsListSelectionListener{ publicvoidvalueChanged(ListSelectionEventevent){ if(!readyList.getValueIsAdjusting()){ Stringid=null,s=null; s=(String)readyList.getSelectedValue(); if(s!=null){ StringTokenizersttokenizer=newStringTokenizer(s,"_"); id=sttokenizer.nextToken(); ProcessPCBreadyItem=readyPCB.getItem(id); if(readyItem!=null) { displayInformation(readyItem); } statuesTextArea.append(readyItem.toString()+"ProcessItem"+id +"inreadyListhasbeendisplayed!\n"); } } } } //内存可分分区表排序,按可用内存大小降序排列 publicvoidsortMemoryList(){ MemoryRecordscurrentListItems=newMemoryRecords(); intnum=memoryItems.getNumberOfItems(); if(num>0){ for(inti=num;i>=1;i--){ IteratormemoryIterator=memoryItems.iterator(); MemoryItemcurrentItem=(MemoryItem)memoryIterator.next(); for(;memoryIterator.hasNext();){ MemoryItemnowItem=(MemoryItem)memoryIterator.next(); if(currentItem.getMemoryLimit()<nowItem.getMemoryLimit()){ currentItem=null; currentItem=nowItem; } } currentListItems.addItem(currentItem); memoryItems.removeItem(currentItem); } memoryItems=null; memoryItems=currentListItems; } memoryList.setListData(memoryItems.getItemsProperties()); } //判断能否为进程分配内存 publicbooleanboolMemoryAllocation(intneededLimit){ if(memoryItems.getNumberOfItems()>0){ IteratormemoryListIteartor=memoryItems.iterator(); MemoryItemlagerestItem=(MemoryItem)memoryListIteartor.next(); if(lagerestItem.getMemoryLimit()>=neededLimit) returntrue; else{ returnfalse; } }else{ returnfalse; } } //内存分配,按最先适应算法原则 publicintMemoryAllocation(intneededLimit){ intcurrentBase=-1,currentLimit=-1; IteratormemoryListIteartor=memoryItems.iterator(); MemoryItemlagerestItem=(MemoryItem)memoryListIteartor.next(); currentBase=lagerestItem.getMemoryBase()+neededLimit; currentLimit=lagerestItem.getMemoryLimit()-neededLimit; memoryItems.removeItem(lagerestItem); if(currentLimit>0){ memoryItems.addItem(newMemoryItem(currentBase,currentLimit)); } sortMemoryList(); returnlagerestItem.getMemoryBase(); } //内存回收 publicvoidmemoryRecall(intnowBase,intnowLimit){ MemoryItemrecallItem=null; intrecalledBase=nowBase; intrecalledLimit=nowLimit; if(memoryItems.getNumberOfItems()>0){ IteratormemoryListIteartor=memoryItems.iterator(); for(;memoryListIteartor.hasNext();){ MemoryItemexistedItem=(MemoryItem)memoryListIteartor.next(); if(existedItem.getMemoryBase()==(nowBase+nowLimit)){ recalledLimit=recalledLimit+existedItem.getMemoryLimit(); memoryItems.removeItem(existedItem); memoryListIteartor=memoryItems.iterator(); }elseif(nowBase==(existedItem.getMemoryBase()+existedItem.getMemoryLimit())){ recalledBase=existedItem.getMemoryBase(); recalledLimit=recalledLimit+existedItem.getMemoryLimit(); memoryItems.removeItem(existedItem); memoryListIteartor=memoryItems.iterator(); } //memoryListIteartor=memoryItems.iterator();//注意此处代码曾引发异常 } //recallItem=newMemoryItem(recalledBase,recalledLimit);//曾产生异常 } recallItem=newMemoryItem(recalledBase,recalledLimit); memoryItems.addItem(recallItem); sortMemoryList(); } publicintreadInteger(Strings){ intnum=-1; try{ num=Integer.parseInt(s); }catch(NumberFormatExceptionnumberformatexception){ statuesTextArea.append("Pleaseinputapositiveinteger!\n"); num=-999; } returnnum; } publicvoidaddToBackupList(StringnewID,ints1,ints2,ints3,Strings){ ProcessPCBitem=backupPCB.getItem(newID); if(item!=null){ statuesTextArea.append("ThePCB"+newID+"hasexistedinBackupList!\n" +"youneedtomodifythePIDoftheselectedPCB!\n"); while(item!=null){ newID=s+newID; item=backupPCB.getItem(newID);} }ProcessPCBnewPCB=newProcessPCB(newID,s1,s2,"Waiting",-1,s3);backupPCB.addItem(newPCB);backupList.setListData(backupPCB.getItemsProperties());backupTotalTextField.setText(Integer.toString(backupPCB.getNumberOfItems())); } publicvoidaddToReadyList(StringnowID,ints1,i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 42125.4-2024测量、控制和实验室用电气设备的安全要求第4部分:气候与环境试验以及其他温度调节设备的特殊要求
- 《光电信息科学与工程专业生产实习》课程教学大纲
- 《民事诉讼法》课程教学大纲
- 计算机专业(基础综合)模拟试卷87(题后含答案及解析)
- 2024年出售转让洗煤机合同范本
- 2024年低成本空房改造合同范本
- 2024年代理充电桩销售合同范本
- 2024年便利店转让五折合同范本
- 江苏省连云港市2024-2025学年九年级上学期期中历史试卷(含答案解析)
- 压疮与失禁的护理
- 高压喷头示意图
- 医院骨科高值耗材使用管理规定
- 绿色施工安全防护措施费用使用计划报审表
- 【教学课件】少年正是读书时示范课件
- 我是节电小能手课件
- Module 5 Unit 1教案 初中英语 外研版 八年级上册 (2022学年)
- 2022年泰安技师学院教师招聘笔试题库及答案解析
- 人教版九年级下册道德与法治全册教案完整版教学设计含教学反思
- 建筑工程勘察项目-技术标
- 道路运输企业职业安全健康管理工作台帐(全版通用)参考模板范本
- TSG 81-2022 场(厂)内专用机动车辆安全技术规程
评论
0/150
提交评论