操作系统实验--进程调度和内存管理---java语言版本(共24页).docx

上传人:飞****2 文档编号:13378417 上传时间:2022-04-29 格式:DOCX 页数:24 大小:259.48KB
返回 下载 相关 举报
操作系统实验--进程调度和内存管理---java语言版本(共24页).docx_第1页
第1页 / 共24页
操作系统实验--进程调度和内存管理---java语言版本(共24页).docx_第2页
第2页 / 共24页
点击查看更多>>
资源描述

《操作系统实验--进程调度和内存管理---java语言版本(共24页).docx》由会员分享,可在线阅读,更多相关《操作系统实验--进程调度和内存管理---java语言版本(共24页).docx(24页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上源代码:第一个类:divDTOpublic class divDTOprivate int divBase;private int length;private int divFlag;public divDTO(int divBase,int length,int divFlag)this.divBase = divBase;this.divFlag = divFlag;this.length = length;public divDTO()public void setDivBase(int base)this.divBase = base;public int

2、getDivBase()return this.divBase;public void setLength(int length)this.length = length;public int getLength()return this.length;public void setDivFlag(int flag)this.divFlag = flag;public int getDivFalg()return this.divFlag;2.第二个类:PcbDTOpublic class PcbDTOstatic final int Running = 1;static final int

3、Ready = 2;static final int Waiting = 3;private String processName;private int runTime;private int prority;private int processState;private int base;private int limit;private int pcbFlag;public PcbDTO(String name, int time,int pro,int base,int limit)this.processName = name;this.runTime = time;this.pr

4、ority = pro;this.processState = 0;this.limit = limit;this.base = base;public PcbDTO()this.pcbFlag = 0;public void setProcessName(String name)this.processName = name;public String getProcessName()return processName;public void setRunTime(int time)this.runTime = time;public int getRunTime()return this

5、.runTime;public void setPrority(int prority)this.prority = prority;public int getPrority()return this.prority;public void setProcessState(int state)this.processState = state;public String getProcessState()String s = new String();if(this.processState = 1)s = running;else if(this.processState = 2)s =

6、ready;else if(this.processState = 3)s = waiting;return s;public int getBase()return this.base;public void setBase(int base)this.base = base;public void setLimit(int limit)this.limit = limit;public int getLimit()return this.limit;第三个类:主类import javax.swing.*;import java.util.*;import java.awt.*;import

7、 java.awt.event.*;import javax.swing.event.*;public class MainFrameprivate JList readyList;private JList waitingList;private JList jobList;private JButton susButton;private JButton relaxButton;private JButton startButton;private JButton newButton;private JLabel nameLabel;private JLabel prorityLabel;

8、private JLabel timeLabel;private JLabel jobLabel;private JLabel readyLabel;private JLabel waitingLabel;private JLabel runningLabel;private JLabel spaceLabel;private JLabel divLabel;private JLabel allocLabel;private JTable readyTable;private JTable runningTable;private JTable divTable;private JTable

9、allocTable;private JTextField nameText;private JTextField timeText;private JTextField spaceText;private JComboBox prorityCom;private JPanel newPanel;private JPanel waitingPanel;private JPanel readyPanel;Vector jobVectorName;Vector jobDtoVector;Vector waitingVectorName;Vector waitingDtoVector;PcbDTO

10、readyDtoArray;PcbDTO newDtoArray;divDTO divDtoArray;PcbDTO newSort;Object readydata;Object runningdata;Object divdata;Object allocdata;int first;int end;int point;PcbDTO a ;public MainFrame()a = new PcbDTO();first = 0;end = 0;point = 0;JFrame jf = new JFrame(进程调度-ws);Container c = jf.getContentPane(

11、);c.setLayout(null);/c.setBackground(Color.pink);newPanel = new JPanel();newPanel.setLayout(null);waitingPanel = new JPanel();waitingPanel.setLayout(null);/waitingPanel.setBackground(Color.pink);readyPanel = new JPanel();readyPanel.setLayout(null);susButton = new JButton(挂起);relaxButton = new JButto

12、n(释放);startButton = new JButton(开始);newButton = new JButton(新建进程);nameLabel = new JLabel(进程名);prorityLabel = new JLabel(优先级);timeLabel = new JLabel(运行时间);jobLabel = new JLabel(后备队列);readyLabel = new JLabel(就绪队列);waitingLabel = new JLabel(等待队列);runningLabel = new JLabel(运行进程);spaceLabel = new JLabel(

13、需要空间);divLabel = new JLabel(未分分区表);allocLabel = new JLabel(内存分配表);nameText = new JTextField();timeText = new JTextField();spaceText = new JTextField();prorityCom = new JComboBox();prorityCom.setToolTipText(优先级);readyDtoArray = new PcbDTO6;newSort = new PcbDTO6;for(int i = 0; i 6;i+)newSorti = new Pc

14、bDTO();newDtoArray = new PcbDTO100;jobDtoVector = new Vector();jobVectorName = new Vector();waitingDtoVector = new Vector();waitingVectorName = new Vector();divDtoArray = new divDTO20;for(int i = 0; i 20; i+)divDtoArrayi = new divDTO();divDtoArrayi.setDivFlag(0);divDtoArray0.setDivFlag(1);divDtoArra

15、y0.setDivBase(20);divDtoArray0.setLength(180);readydata = new Object64;runningdata = new Object23;divdata = new Object203;allocdata = new Object203;String col1 = 进程,时间,优先级,状态;String col2 = 进程,时间,优先级;String col3 = 起址,长度,状态;String col4 = 起址,长度,占用进程; readyTable = new JTable(readydata,col1);/readyTable.

16、setEnabled(false);runningTable = new JTable(runningdata,col2);runningTable.setRowHeight(22);runningTable.setEnabled(false);allocTable = new JTable(allocdata,col4);allocTable.setEnabled(false);divTable = new JTable(divdata,col3);divTable.setEnabled(false);divTable.setValueAt(String.valueOf(20),0,0);d

17、ivTable.setValueAt(String.valueOf(180),0,1);divTable.setValueAt(String.valueOf(1),0,2);JScrollPane runningSP = new JScrollPane();JScrollPane readySP2 = new JScrollPane();JScrollPane divSP = new JScrollPane();JScrollPane allocSP = new JScrollPane();runningSP.getViewport().add(runningTable);readySP2.g

18、etViewport().add(readyTable);divSP.getViewport().add(divTable);allocSP.getViewport().add(allocTable);/int prorityArray = new int10;for(int i = 0;i readyDtoArraymax.getPrority()max = j;j = (j+1)%6;if(max=0)a = readyDtoArraymax;readyDtoArraymax = readyDtoArrayfirst;readyDtoArrayfirst = a;readyTable.se

19、tValueAt(readyDtoArraymax.getProcessName(),max,0);readyTable.setValueAt(readyDtoArraymax.getRunTime(),max,1);readyTable.setValueAt(readyDtoArraymax.getPrority(),max,2);readyTable.setValueAt(readyDtoArraymax.getProcessState(),max,3);readyTable.setValueAt(,first,0);readyTable.setValueAt(,first,1);read

20、yTable.setValueAt(,first,2);readyTable.setValueAt(,first,3);runningTable.setValueAt(a.getProcessName(),0,0);runningTable.setValueAt(a.getRunTime(),0,1);runningTable.setValueAt(a.getPrority(),0,2);readyDtoArrayfirst.setRunTime(readyDtoArrayfirst.getRunTime()-1);if(0 != readyDtoArrayfirst.getPrority()

21、readyDtoArrayfirst.setPrority(readyDtoArrayfirst.getPrority()-1);first = (first+1)%6;elseSystem.out.println(cpu等待中);else /*tryThread.sleep(2000);catch(InterruptedException e1)System.out.println(e1);*/System.out.println(到1);runningTable.setValueAt(,0,0);runningTable.setValueAt(,0,1);runningTable.setV

22、alueAt(,0,2);/如果运行时间为0则撤销进程,否则将进程重新添加到就绪队列中if( a.getRunTime()=0)/收回内存空间for(int i = 0;i =a.getBase()newSorti = newSorti+1;point-;/设置内存分配表的内容for(int i = 0; i point;i+)allocTable.setValueAt(String.valueOf(newSorti.getBase(),i,0);allocTable.setValueAt(String.valueOf(newSorti.getLimit(),i,1);allocTable.s

23、etValueAt(newSorti.getProcessName(),i,2); allocTable.setValueAt(,point,0);allocTable.setValueAt(,point,1);allocTable.setValueAt(,point,2);/把收回的内存加入到记录未分分区的数组int memoryEnd = 0;int location = 0;int up = -1;/int down = -1;for(int i = 0;i= 0&down = 0)divDtoArrayup.setLength(divDtoArrayup.getLength()+a.g

24、etLimit()+divDtoArraydown.getLength();divDtoArraydown.setDivFlag(0);for(int i = (down+1); i = 0&down 0)divDtoArrayup.setLength(divDtoArrayup.getLength()+a.getLimit();else if(up = 0)divDtoArraydown.setLength(divDtoArraydown.getLength()+a.getLimit();divDtoArraydown.setDivBase(a.getBase();else if(up 0&down 0)for(int i = 0; i a.getBase()|divDtoArrayi.getDivFalg()=0)location = i;break; for(int i = 20; i location;i-) if(divDtoArray

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁