收藏 分享(赏)

操作系统实验 进程调度和内存管理 java语言版本.doc

上传人:精品资料 文档编号:9852278 上传时间:2019-09-11 格式:DOC 页数:24 大小:262.19KB
下载 相关 举报
操作系统实验  进程调度和内存管理   java语言版本.doc_第1页
第1页 / 共24页
操作系统实验  进程调度和内存管理   java语言版本.doc_第2页
第2页 / 共24页
操作系统实验  进程调度和内存管理   java语言版本.doc_第3页
第3页 / 共24页
操作系统实验  进程调度和内存管理   java语言版本.doc_第4页
第4页 / 共24页
操作系统实验  进程调度和内存管理   java语言版本.doc_第5页
第5页 / 共24页
点击查看更多>>
资源描述

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 getDivBase()r

2、eturn 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 Ready = 2;sta

3、tic 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.prority = pro;t

4、his.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.runTime;publ

5、ic 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 = “ready“;els

6、e 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 java.a

7、wt.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;private

8、 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 allocTa

9、ble;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 readyDt

10、oArray;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();c.s

11、etLayout(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 JButton(“

12、释放“);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(“运行进程“);spaceLa

13、bel = new JLabel(“需要空间“);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;

14、 i readyDtoArraymax.getPrority()max = j;j = (j+1)%6;if(max=0)a = readyDtoArraymax;readyDtoArraymax = readyDtoArrayfirst;readyDtoArrayfirst = a;readyTable.setValueAt(readyDtoArraymax.getProcessName(),max,0);readyTable.setValueAt(readyDtoArraymax.getRunTime(),max,1);readyTable.setValueAt(readyDtoArray

15、max.getPrority(),max,2);readyTable.setValueAt(readyDtoArraymax.getProcessState(),max,3);readyTable.setValueAt(“,first,0);readyTable.setValueAt(“,first,1);readyTable.setValueAt(“,first,2);readyTable.setValueAt(“,first,3);runningTable.setValueAt(a.getProcessName(),0,0);runningTable.setValueAt(a.getRun

16、Time(),0,1);runningTable.setValueAt(a.getPrority(),0,2);readyDtoArrayfirst.setRunTime(readyDtoArrayfirst.getRunTime()-1);if(0 != readyDtoArrayfirst.getPrority()readyDtoArrayfirst.setPrority(readyDtoArrayfirst.getPrority()-1);first = (first+1)%6;elseSystem.out.println(“cpu 等待中 “);else /*tryThread.sle

17、ep(2000);catch(InterruptedException e1)System.out.println(e1);*/System.out.println(“到 1“);runningTable.setValueAt(“,0,0);runningTable.setValueAt(“,0,1);runningTable.setValueAt(“,0,2);/如果运行时间为 0 则撤销进程,否则将进程重新添加到就绪队列中if( a.getRunTime()=a.getBase()newSorti = newSorti+1;point-;/设置内存分配表的内容for(int i = 0;

18、i = 0divDtoArraydown.setDivFlag(0);for(int i = (down+1); i = 0divDtoArraydown.setDivBase(a.getBase();else if(up a.getBase()|divDtoArrayi.getDivFalg()=0)location = i;break;for(int i = 20; i location;i-)if(divDtoArrayi-1.getDivFalg()=1)divDtoArrayi.setDivBase(divDtoArrayi-1.getDivBase();divDtoArrayi.s

19、etDivFlag(1);divDtoArrayi.setLength(divDtoArrayi-1.getLength();divDtoArraylocation.setDivBase(a.getBase();divDtoArraylocation.setDivFlag(1);divDtoArraylocation.setLength(a.getLimit();/设置未分分区表的内容for(int i = 0; i = jobToReady.getLimit()runAllocFlag = i;break;if(runAllocFlag = 0)jobDtoVector.removeElem

20、entAt(0);jobVectorName.remove(jobVectorName.indexOf(jobToReady.getProcessName();jobList.setListData(jobVectorName);jobToReady.setProcessState(PcbDTO.Ready);jobToReady.setBase(divDtoArrayrunAllocFlag.getDivBase();runLength = divDtoArrayrunAllocFlag.getLength()- jobToReady.getLimit();if(runLength = 0)

21、int i = runAllocFlag;divDtoArrayi.setDivFlag(0);for(; i 0)int c2 = divDtoArrayrunAllocFlag.getDivBase()+ jobToReady.getLimit();divDtoArrayrunAllocFlag.setDivBase(c2);divDtoArrayrunAllocFlag.setLength(runLength);divTable.setValueAt(String.valueOf(c2),runAllocFlag,0);divTable.setValueAt(String.valueOf

22、(runLength),runAllocFlag,1);divTable.setValueAt(String.valueOf(divDtoArrayrunAllocFlag.getDivFalg(),runAllocFlag,2);readyDtoArrayend = jobToReady;readyTable.setValueAt(jobToReady.getProcessName(),end,0);readyTable.setValueAt(jobToReady.getRunTime(),end,1);readyTable.setValueAt(jobToReady.getPrority(

23、),end,2);readyTable.setValueAt(jobToReady.getProcessState(),end,3);end = (end+1)%6;int runi = 0;/用于记录当前新生成的 PcbDTO 对象应该插入到 newSort 中的位置for(; runi runi; i-)newSorti = newSorti-1;allocTable.setValueAt(String.valueOf(newSorti.getBase(),i,0);allocTable.setValueAt(String.valueOf(newSorti.getLimit(),i,1);

24、allocTable.setValueAt(newSorti.getProcessName(),i,2);/插入新生成的对象newSortruni = jobToReady;allocTable.setValueAt(String.valueOf(jobToReady.getBase(),runi,0);allocTable.setValueAt(String.valueOf(jobToReady.getLimit(),runi,1);allocTable.setValueAt(jobToReady.getProcessName(),runi,2);point+;else readyDtoAr

25、rayend = a;readyTable.setValueAt(a.getProcessName(),end,0);readyTable.setValueAt(a.getRunTime(),end,1);readyTable.setValueAt(a.getPrority(),end,2);readyTable.setValueAt(a.getProcessState(),end,3);end = (end+1)%6;/else if(jb = newButton)int newAllocFlag = -1;int newLength = 0;if(nameText.getText().tr

26、im().length() = 0)JOptionPane.showMessageDialog(null,“进程名不能为空!“);else if(timeText.getText().trim().length() = 0)JOptionPane.showMessageDialog(null,“运行时间不能为空“);else if(spaceText.getText().trim().length() = 0)JOptionPane.showMessageDialog(null,“空间不能为空“);elsetest.setRunTime(Integer.parseInt(timeText.ge

27、tText();test.setLimit(Integer.parseInt(spaceText.getText();String s = prorityCom.getSelectedItem().toString();test.setPrority(Integer.parseInt(s);test.setProcessName(nameText.getText().trim();newDtoArraycount = test;jobDtoVector.add(newDtoArraycount);jobVectorName.add(newDtoArraycount.getProcessName

28、();jobList.setListData(jobVectorName);count+;nameText.setText(“);timeText.setText(“);spaceText.setText(“);PcbDTO b = (PcbDTO)jobDtoVector.elementAt(0);for(int i = 0; i = b.getLimit()newAllocFlag = i;break;/在就绪队列未满且内存有足够空间时将后备队列 jobDtoVetor 中的对象添加到就绪队列中if(end + 2)%6 != firstb.setProcessState(PcbDTO.R

29、eady);b.setBase(divDtoArraynewAllocFlag.getDivBase();newLength = divDtoArraynewAllocFlag.getLength()- b.getLimit();if(newLength = 0)int i = newAllocFlag;divDtoArrayi.setDivFlag(0);for(; i 0)int c1 = divDtoArraynewAllocFlag.getDivBase()+ b.getLimit();divDtoArraynewAllocFlag.setDivBase(c1);divDtoArray

30、newAllocFlag.setLength(newLength);divTable.setValueAt(String.valueOf(c1),newAllocFlag,0);divTable.setValueAt(String.valueOf(newLength),newAllocFlag,1);divTable.setValueAt(String.valueOf(divDtoArraynewAllocFlag.getDivFalg(),newAllocFlag,2);readyDtoArrayend = b;jobVectorName.remove(jobVectorName.index

31、Of(b.getProcessName();readyTable.setValueAt(b.getProcessName(),end,0);readyTable.setValueAt(b.getRunTime(),end,1);readyTable.setValueAt(b.getPrority(),end,2);readyTable.setValueAt(“ready“,end,3);end =(end+1)%6;int newi = 0;/用于记录当前新生成的 PcbDTO 对象应该插入到newSort 中的位置for(; newi newi; i-)newSorti = newSorti

32、-1;allocTable.setValueAt(String.valueOf(newSorti.getBase(),i,0);allocTable.setValueAt(String.valueOf(newSorti.getLimit(),i,1);allocTable.setValueAt(newSorti.getProcessName(),i,2);/插入新生成的对象newSortnewi = b;allocTable.setValueAt(String.valueOf(b.getBase(),newi,0);allocTable.setValueAt(String.valueOf(b.

33、getLimit(),newi,1);allocTable.setValueAt(b.getProcessName(),newi,2);point+;else if(jb = susButton)if(readyDtoArrayreadyTable.getSelectedRow() != null)if(!readyDtoArrayreadyTable.getSelectedRow().getProcessState().equals(“waiting“)readyDtoArrayreadyTable.getSelectedRow().setProcessState(PcbDTO.Waitin

34、g);readyTable.setValueAt(“waiting“,readyTable.getSelectedRow(),3);waitingDtoVector.add(readyDtoArrayreadyTable.getSelectedRow();waitingVectorName.add(readyDtoArrayreadyTable.getSelectedRow().getProcessName();waitingList.setListData(waitingVectorName);elseSystem.out.println(“已挂起“);elseJOptionPane.sho

35、wMessageDialog(null,“请选择要挂起的进程“);/System.out.println(“请选择要挂起的进程“);else if(jb = relaxButton)String s = (String)waitingList.getSelectedValue();if(s != null)waitingVectorName.remove(s);PcbDTO p = new PcbDTO();for(int i = 0; i waitingDtoVector.size(); i+)p = (PcbDTO)waitingDtoVector.elementAt(i);if(s.eq

36、uals(p.getProcessName()p.setProcessState(PcbDTO.Ready);waitingDtoVector.remove(p);break;for(int i = 0;i 6;i+)if(s.equals(readyDtoArrayi.getProcessName()readyTable.setValueAt(“ready“,i,3);break;waitingList.setListData(waitingVectorName);elseJOptionPane.showMessageDialog(null,“请选择要解挂的进程“);/System.out.println(“没有选择的进程“);public static void main(String args)new MainFrame();相关截图如下:运行后开始界面 输入进程后界面建立后挂起 挂起后各内存分配 解挂操作异常时的提示

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报