ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:17.14KB ,
资源ID:3461628      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3461628.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java模拟操作系统进程调时间片轮换法.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

java模拟操作系统进程调时间片轮换法.docx

1、java模拟操作系统进程调时间片轮换法/* * * 设计PCB及其数据结构: 进程标识数:ID 进程优先数:PRIORITY(优先数越大,优先级越高) * 进程已占用时间片:CPUTIME,每得到一次调度,值加1; * 进程还需占用时间片:ALLTIME,每得到一次调度,该值减1,一旦运行完毕,ALLTIME为0) 进程队列指针:NEXT,用来将PCB排成队列 * 进程状态:STATE(一般为就绪,可以不用) 设计进程就绪队列及数据结构; 设计进程调度算法,并画出程序流程图; 设计输入数据和输出格式; * 结构格式:当前正运行的进程:0 当前就绪队列:2,1,3,4 编程上机,验证结果 * *

2、 */public class PCB private int id; private int priority; private int cpuTime; private int allTime; private int state;/ 状态为1的时候表示准备就绪 /* * 无参数的构造方法,通过geter,seter器来对PCB的信息进行获取的修改 */ public PCB() /* * 初始化PCB的基本信息的构造方法 * * param id * param priority * param cpuTime * param allTime * param state */ publi

3、c PCB(int id, int priority, int cpuTime, int allTime, int state) super(); this.id = id; this.priority = priority; this.cpuTime = cpuTime; this.allTime = allTime; this.state = state; public int getId() return id; public void setId(int id) this.id = id; public int getPriority() return priority; public

4、 void setPriority(int priority) this.priority = priority; /* * 根据要求来修改PCB的优先级 */ public void modifyPriority() if (0 this.priority) this.priority -= 3; return; public int getCpuTime() return cpuTime; public void setCpuTime(int cpuTime) this.cpuTime = cpuTime; /* * 根据要求修改CPU时间 */ public void modifyCpu

5、Time() this.cpuTime += 1; public int getAllTime() return allTime; public void setAllTime(int allTime) this.allTime = allTime; /* * 根据要求修改PCB占用的时间片 */ public void modifyAllTime() if (0 this.allTime) this.allTime -= 1; return; public int getState() return state; public void setState(int state) this.st

6、ate = state; /* * 根据要求修改PCB的状态 */ public void midifyState() /* * 打印显示当前PCB的全部信息 */ public void showStatus() System.out.println(PCB id= + id + , priority= + priority + , cpuTime= + cpuTime + , allTime= + allTime + , state= + state + ); /* * 修改PCB的全部信息 */ public void modify() if (0 this.allTime) this.

7、allTime -= 1; this.cpuTime += 1; if (0 this.priority) this.priority -= 3; * 创建PCB的数据结构 * * author * */public class LineListNode private LineListNode node; private T element; /* * 创建空链表 */ public LineListNode() this.node = null; this.element = null; /* * 创建一个存储特定元素的线性表 */ public LineListNode(T elemen

8、t) this.node = null; this.element = element; /* * 返回当前结点点的下一个节点 */ public LineListNode getNextNode() return this.node; /* * 设置当前结点的下一个结点 */ public void setNextNode(LineListNode node) this.node = node; /* * 返回当前结点存储的数据元素 */ public T getElement() return this.element; /* * 设置当前结点存储的数据元素 */ public void

9、setElement(T element) this.element = element; /* * 创建一个存储PCB用来线性链表,通过线性链表的相关操作来实现相应的功能 * * author * */public class LineListPcb /* * 表示PCB线性表的长度 */ private int size; /* * 表示PCB线性表的头元素结点 */ private LineListNode headPcb; /* * 表示PCB线性表尾元素结点 */ private LineListNode lastPcb; /* * 创建一个空的PCB线性存储链表 */ public

10、 LineListPcb() this.size = 0; this.headPcb = null; this.lastPcb = this.headPcb; /* * 创建一个具有特定元素的PCB线性存储链表 */ public LineListPcb(LineListPcb llp) this.size = llp.getSize(); this.headPcb = llp.getHeadPcb(); this.lastPcb = llp.getLastPcb(); /* * 从PCB线性表中的头部移除数据元素 * * param element */ public void remove

11、Element() if (0 = this.size) return; SuppressWarnings(unused) LineListNode tempNode = this.headPcb; this.headPcb = this.headPcb.getNextNode(); tempNode = null; this.size-; /* * 这一段主要是为了处理移除数据元素后只剩下一个数据元素的时候的线性链表处理 */ if (this.size = 1) this.headPcb.setNextNode(this.lastPcb); this.lastPcb = this.head

12、Pcb; this.lastPcb.setNextNode(null); /* * 向PCB线性表中的添加数据元素 * * param element */ public void addElement(T element) LineListNode newElement = new LineListNode(element); if (this.headPcb = null) /* * 头结点为空,表示链表中当前没有数据元素,说明头结点和尾结点指向同一内存空间 */ this.headPcb = newElement; /* * 新添加一个数据元素则仍然指向同一内存空间 */ this.la

13、stPcb = this.headPcb; else /* * 链表不为空,在这里要保证最后一个结点与新加入的结点连接在一起 */ this.lastPcb.setNextNode(newElement); this.lastPcb = newElement; this.size+; /* * 从PCB线性表中的头部移除数据元素,并将其添加到PCB线性表中的尾部 */ public void removeFromHeadAddToLast() if (this.size = 1) return; LineListNode tempNode = this.headPcb; this.headPc

14、b = tempNode.getNextNode(); this.lastPcb.setNextNode(tempNode); this.lastPcb = tempNode; /* * 从PCB线性表中中的尾部移除数据元素,并将其添加到PCB的线性表中的头部 */ public void removeFromLastAddToHead() if (0 = this.size) return; LineListNode tempNode = this.lastPcb; /* * 设置尾结点的以一个结点为空 */ LineListNode lastSecondNode = this.headPc

15、b; /* * i=1表示指向PCB线性表的元素为线性表的第一个元素 * i=this.size-1表示指向线性表的元素为线性表的末尾第二个数据元素 */ for (int i = 1; i this.size - 1; i+) lastSecondNode = lastSecondNode.getNextNode(); lastSecondNode.setNextNode(null); /* * 设置PCB线性表尾结点的下一个结点为头结点的下一个结点,头结点为为尾结点 */ tempNode.setNextNode(this.headPcb.getNextNode(); this.headP

16、cb = tempNode; /* * 判断PCB线性表是否为空 */ public boolean isEmpty() return this.size = 0; /* * return the headPcb */ public LineListNode getHeadPcb() return this.headPcb; /* * return the lastPcb */ public LineListNode getLastPcb() return this.lastPcb; /* * * return PCB */ public T getPCB() return this.head

17、Pcb.getElement(); /* * param headPcb * the headPcb to set */ public void setHeadPcb(LineListNode headPcb) this.headPcb = headPcb; /* * return the size */ public int getSize() return this.size; /* * param size * the size to set */ public void setSize(int size) this.size = size; public class PCBProces

18、s public static void main(String args) PCB p = new PCB(0, 9, 0, 3, 1), new PCB(1, 38, 0, 2, 1), new PCB(2, 30, 0, 6, 1), new PCB(3, 29, 0, 3, 1), new PCB(4, 0, 0, 4, 1); LineListPcb llp = new LineListPcb(); for (int i = 0; i p.length; i+) llp.addElement(pi); while (true) if (llp.getSize() = 0) break

19、; LineListNode lln = llp.getHeadPcb(); PCB pcb = lln.getElement(); pcb.modify(); System.out.print(进程 + pcb.getId() + 正在占用时间片); pcb.showStatus(); if (0 != pcb.getAllTime() System.out.println(); llp.removeFromHeadAddToLast(); else System.out.println(); System.out.println(* + 进程 + pcb.getId() + 获得执行,并且移除就绪队列 + *); System.out.println(); llp.removeElement();

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1