操作系统实验报告-中南大学_第1页
操作系统实验报告-中南大学_第2页
操作系统实验报告-中南大学_第3页
操作系统实验报告-中南大学_第4页
操作系统实验报告-中南大学_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、操作系统原理试验报告班级: 学号:姓名:实验一:CPU调度一、实验内容 选择一个调度算法,实现处理机调度。二、实验目的 多道系统中,当就绪进程数大于处理机数时,须按照某种策略决定哪些进程优先占用处理机。本实验模拟实现处理机调度,以加深了解处理机调度的工作。三、实验题目 1、设计一个按优先权调度算法实现处理机调度的程序; 2、设计按时间片轮转实现处理机调度的程序。四、实验要求PCB内容: 进程名/PID; 要求运行时间(单位时间); 优先权; 状态: PCB指针;1、可随机输入若干进程,并按优先权排序;2、从就绪队首选进程运行:优先权-1/要求运行时间-1 要求运行时间=0时,撤销该进程3、重新

2、排序,进行下轮调度4、最好采用图形界面;5、可随时增加进程;6、规定道数,设置后备队列和挂起状态。若内存中进程少于规定道数,可自动从后备队列调度一作业进入。被挂起进程入挂起队列,设置解挂功能用于将指定挂起进程解挂入就绪队列。7、每次调度后,显示各进程状态。实验二:内存管理一、实验内容 主存储器空间的分配和回收二、实验目的 帮助了解在不同的存储管理方式下,应怎样实现主存空间的分配和回收。三、实验题目 在可变分区管理方式下,采用最先适应算法实现主存空间的分配和回收。 四、实验要求1、自行假设主存空间大小,预设操作系统所占大小并构造未分分区表; 表目内容:起址、长度、状态(未分/空表目)2、结合实验

3、一,PCB增加为: PID,要求运行时间,优先权,状态,所需主存大小,主存起始位置,PCB指针3、采用最先适应算法分配主存空间;4、进程完成后,回收主存,并与相邻空闲分区合并.1、Vo类说明(数据存储结构)进程控制块PCB的结构:Public class PCB /进程控制块PCB,代表一个进程/进程名,作为进程的标识;private String name; /要求运行时间,假设进程运行的单位时间数;private int time; /赋予进程的优先权,调度时总是选取优先数小的进程先执行;private int priority; /状态,假设有“就绪”状态(ready)、“运行”状态(r

4、unning)、/“后备”状态(waiting)、“挂起”状态(handup)private String state; /进程存放在table中的位置private int start; /进程的大小private int length;/进程是否进入内存, 1为进入,0为未进入private int isIn;/进程在内存中的起始位置private int base; /进程的大小private int limit; /一些get和set方法以及构造器 省略 ;2流程图3.源程序核心代码public void display()if(runningList.size()>0)jt1.

5、setValueAt(runningList.get(0).getName().trim(),0,0);jt1.setValueAt(runningList.get(0).getIsIn(),0,1);jt1.setValueAt(runningList.get(0).getTime(),0,2);jt1.setValueAt(runningList.get(0).getPriority(),0,3);jt1.setValueAt(runningList.get(0).getStart(),0,4);jt1.setValueAt(runningList.get(0).getLength(),0

6、,5);elsejt1.setValueAt("无进程",0,0);jt1.setValueAt("进行",0,1);jt1.setValueAt(null,0,2);jt1.setValueAt(null,0,3);jt1.setValueAt(null,0,4);jt1.setValueAt(null,0,5);/for(int i =0; i < readyList.size(); i+)jt2.setValueAt(readyList.get(i).getName().trim(),i,0);jt2.setValueAt(readyList

7、.get(i).getIsIn(),i,1);jt2.setValueAt(readyList.get(i).getTime(),i,2);jt2.setValueAt(readyList.get(i).getPriority(),i,3);jt2.setValueAt(readyList.get(i).getStart(),i,4);jt2.setValueAt(readyList.get(i).getLength(),i,5);for(int j = readyList.size(); j < 6; j+)jt2.setValueAt(null,j,0);jt2.setValueAt

8、(null,j,1);jt2.setValueAt(null,j,2);jt2.setValueAt(null,j,3);jt2.setValueAt(null,j,4);jt2.setValueAt(null,j,5);/for(int i =0; i < waitingList.size(); i+)jt3.setValueAt(waitingList.get(i).getName().trim(),i,0);jt3.setValueAt(waitingList.get(i).getIsIn(),i,1);jt3.setValueAt(waitingList.get(i).getTi

9、me(),i,2);jt3.setValueAt(waitingList.get(i).getPriority(),i,3);jt3.setValueAt(waitingList.get(i).getStart(),i,4);jt3.setValueAt(waitingList.get(i).getLength(),i,5);for(int j = waitingList.size(); j < 15; j+)jt3.setValueAt(null,j,0);jt3.setValueAt(null,j,1);jt3.setValueAt(null,j,2);jt3.setValueAt(

10、null,j,3);jt3.setValueAt(null,j,4);jt3.setValueAt(null,j,5);/for(int i =0; i < handupList.size(); i+)jt4.setValueAt(handupList.get(i).getName().trim(),i,0);jt4.setValueAt(handupList.get(i).getIsIn(),i,1);jt4.setValueAt(handupList.get(i).getTime(),i,2);jt4.setValueAt(handupList.get(i).getPriority(

11、),i,3);jt4.setValueAt(handupList.get(i).getStart(),i,4);jt4.setValueAt(handupList.get(i).getLength(),i,5);for(int j = handupList.size(); j < 15; j+)jt4.setValueAt(null,j,0);jt4.setValueAt(null,j,1);jt4.setValueAt(null,j,2);jt4.setValueAt(null,j,3);jt4.setValueAt(null,j,4);jt4.setValueAt(null,j,5)

12、;jl1.setCellRenderer(new MyRenderer();for(int i = 0; i < unAssignList.size(); i+)System.out.print(unAssignList.get(i).getBase()+" ");System.out.println(unAssignList.get(i).getLimit();System.out.println("one");System.out.println();/时间和优先级减一 public void sub() if(runningList.size

13、()>0&&runningList.get(0).getIsIn()=1) runningList.get(0).setTime(runningList.get(0).getTime()-1); if(runningList.get(0).getPriority()>=1)runningList.get(0).setPriority(runningList.get(0).getPriority()-1); if(runningList.get(0).getTime()<0) runningList.get(0).setTime(0); if(runningLi

14、st.get(0).getTime()=0) putOutMemory(runningList,0); public void sub1() if(runningList.size()>0&&runningList.get(0).getIsIn()=1) runningList.get(0).setTime(runningList.get(0).getTime()-1);if(runningList.get(0).getTime()=0) putOutMemory(runningList,0); if(runningList.get(0).getPriority()<

15、;15) if(runningList.get(0).getPriority()>=1)runningList.get(0).setPriority(runningList.get(0).getPriority()-1); / public class MyRunnable implements Runnable public void run() while(true)timeManager();try Thread.sleep(1000); catch(InterruptedException ex) /自动调度/ public class MyRunnable1 implement

16、s Runnable public void run() while(true)PManager(); try Thread.sleep(1000); catch(InterruptedException ex) /得到list中优先权最高的/ public int getFirstW(ArrayList<Data> list) if(list.size()>0) int min = 0; for(int i = 1;i<list.size();i+ ) if(list.get(min).getPriority() > list.get(i).getPriorit

17、y() min = i; min+; return min; else return 0; / /删除列表中第几个数据/ / public void update(ArrayList<Data> list, int num) sList.clear();for(int i = 0; i < list.size(); i+)if(i != num)sList.add(list.get(i);list.clear();for(int i = 0; i < sList.size();i+)list.add(sList.get(i); public void update1(A

18、rrayList<Data_Memory> list, int num) sList1.clear();for(int i = 0; i < list.size(); i+)if(i != num)sList1.add(list.get(i);list.clear();for(int i = 0; i < sList1.size();i+)list.add(sList1.get(i); / /放入内存/ / public void putInMemory() if(runningList.size()>0) if(runningList.get(0).getIsI

19、n()=0) for(int i = 0; i < unAssignList.size(); i+) if(unAssignList.get(i).getLimit() >= runningList.get(0).getLength() runningList.get(0).setStart(unAssignList.get(i).getBase(); runningList.get(0).setIsIn(1); if(unAssignList.get(i).getLimit() = runningList.get(0).getLength() update1(unAssignLi

20、st,i); else unAssignList.get(i).setBase(unAssignList.get(i).getBase()+runningList.get(0).getLength(); unAssignList.get(i).setLimit(unAssignList.get(i).getLimit()-runningList.get(0).getLength(); break; if(readyList.size()>0) for(int j = 0; j < readyList.size(); j+) if(readyList.get(j).getIsIn()

21、=0) for(int i = 0; i < unAssignList.size(); i+) if(unAssignList.get(i).getLimit() >= readyList.get(j).getLength() readyList.get(j).setStart(unAssignList.get(i).getBase(); readyList.get(j).setIsIn(1); if(unAssignList.get(i).getLimit() = readyList.get(j).getLength() update1(unAssignList,i); else

22、 unAssignList.get(i).setBase(unAssignList.get(i).getBase()+readyList.get(j).getLength(); unAssignList.get(i).setLimit(unAssignList.get(i).getLimit()-readyList.get(j).getLength(); break; / /移除内存/ / public void putOutMemory(ArrayList<Data> list, int num) list.get(num).setIsIn(0); boolean flag1 =

23、 false; boolean flag2 = false; for(int i = 0; i < unAssignList.size(); i+) if(unAssignList.get(i).getBase() = (list.get(num).getLength()+list.get(num).getStart() unAssignList.get(i).setBase(list.get(num).getStart(); unAssignList.get(i).setLimit(list.get(num).getLength()+unAssignList.get(i).getLim

24、it(); flag1 = true; break; for(int i = 0; i < unAssignList.size(); i+) if(unAssignList.get(i).getBase()+unAssignList.get(i).getLimit() = list.get(num).getStart() if(!flag1) unAssignList.get(i).setLimit(list.get(num).getLength()+unAssignList.get(i).getLimit(); flag2 = true; break; else unAssignLis

25、t.get(i).setLimit(unAssignList.get(i).getLimit()+unAssignList.get(i+1).getLimit(); update1(unAssignList,i+1); if(flag1 | flag2) else int i = 0; while(unAssignList.get(i).getBase()<list.get(num).getStart() i+; Data_Memory data = new Data_Memory(); data.setBase(list.get(num).getStart(); data.setLim

26、it(list.get(num).getLength(); sList1.clear(); for(int j = 0; j < i; j+) sList1.add(unAssignList.get(j); sList1.add(data); for(int j = i; j < unAssignList.size(); j+) sList1.add(unAssignList.get(j); unAssignList.clear(); for(int j = 0; j < sList1.size(); j+) unAssignList.add(sList1.get(j); /

27、 / /JLIST private class MyRenderer extends DefaultListCellRenderer public Component getListCellRendererComponent(JList list, Object value,int index, boolean isSelected, boolean cellHasFocus) super.getListCellRendererComponent(list, value, index, isSelected,cellHasFocus); setBackground(Color.gray); f

28、or(int i = 0; i < unAssignList.size(); i+) for(int j = unAssignList.get(i).getBase() ; j < unAssignList.get(i).getLimit()+unAssignList.get(i).getBase(); j+) if(index = j) setBackground(Color.white);/当没有内容变为白色 return this; / / public void timeManager() /去掉time=0的,从waiting队列加入新的进程,排序,调整waitingLi

29、st加入runningLIst/去掉time=0的if(runningList.size()>0)if(runningList.get(0).getTime()=0)runningList.clear();sList.clear();for(int i = 0; i < readyList.size(); i+)if(readyList.get(i).getTime()>0)sList.add(readyList.get(i);readyList.clear();for(int i =0; i < sList.size();i+)readyList.add(sList.

30、get(i);readyList.get(i).setState("ready");/从waiting队列加入新的进程int j = 0;int m = readyList.size();for(; m < 6 && j < waitingList.size(); m+,j+)readyList.add(waitingList.get(j);readyList.get(m).setState("ready");/sort(readyList);/调整waitingListsList.clear();for(int i = j;

31、 i < waitingList.size(); i+)sList.add(waitingList.get(i);waitingList.clear();for(int i =0; i < sList.size();i+)waitingList.add(sList.get(i);/加入runningLIstif(runningList.size()=0)if(readyList.size()>0)runningList.add(readyList.get(0);runningList.get(0).setState("running");update(re

32、adyList,0);if(waitingList.size()>0)readyList.add(waitingList.get(0);readyList.get(5).setState("ready");update(waitingList,0);else /if(runningList.size()>0)if(readyList.size()>0)readyList.add(runningList.get(0);runningList.clear();readyList.get(0).setState("running");read

33、yList.get(readyList.size()-1).setState("ready");runningList.add(readyList.get(0);update(readyList,0);putInMemory();sub();display();jtf1.grabFocus(); public void PManager() if(runningList.size()>0) if(runningList.get(0).getTime()=0) runningList.clear(); sList.clear(); for(int i = 0; i &l

34、t; readyList.size(); i+) if(readyList.get(i).getTime()>0) sList.add(readyList.get(i); readyList.clear(); for(int i =0; i < sList.size();i+) readyList.add(sList.get(i); readyList.get(i).setState("ready"); /从waiting队列加入新的进程 int j = 0; int m = readyList.size(); for(; m < 6 && j &l

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论