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

上传人:b****3 文档编号:3461628 上传时间:2022-11-23 格式:DOCX 页数:13 大小:17.14KB
下载 相关 举报
java模拟操作系统进程调时间片轮换法.docx_第1页
第1页 / 共13页
java模拟操作系统进程调时间片轮换法.docx_第2页
第2页 / 共13页
java模拟操作系统进程调时间片轮换法.docx_第3页
第3页 / 共13页
java模拟操作系统进程调时间片轮换法.docx_第4页
第4页 / 共13页
java模拟操作系统进程调时间片轮换法.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

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

《java模拟操作系统进程调时间片轮换法.docx》由会员分享,可在线阅读,更多相关《java模拟操作系统进程调时间片轮换法.docx(13页珍藏版)》请在冰豆网上搜索。

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

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

/**

*

*①设计PCB及其数据结构:

进程标识数:

ID进程优先数:

PRIORITY(优先数越大,优先级越高)

*进程已占用时间片:

CPUTIME,每得到一次调度,值加1;

*进程还需占用时间片:

ALLTIME,每得到一次调度,该值减1,一旦运行完毕,ALLTIME为0)进程队列指针:

NEXT,用来将PCB排成队列

*进程状态:

STATE(一般为就绪,可以不用)②设计进程就绪队列及数据结构;③设计进程调度算法,并画出程序流程图;④设计输入数据和输出格式;

*结构格式:

当前正运行的进程:

0当前就绪队列:

2,1,3,4⑤编程上机,验证结果

*

*

*/

publicclassPCB{

privateintid;

privateintpriority;

privateintcpuTime;

privateintallTime;

privateintstate;//状态为1的时候表示准备就绪

/**

*无参数的构造方法,通过geter,seter器来对PCB的信息进行获取的修改

*/

publicPCB(){

}

/**

*初始化PCB的基本信息的构造方法

*

*@paramid

*@parampriority

*@paramcpuTime

*@paramallTime

*@paramstate

*/

publicPCB(intid,intpriority,intcpuTime,intallTime,intstate){

super();

this.id=id;

this.priority=priority;

this.cpuTime=cpuTime;

this.allTime=allTime;

this.state=state;

}

publicintgetId(){

returnid;

}

publicvoidsetId(intid){

this.id=id;

}

publicintgetPriority(){

returnpriority;

}

publicvoidsetPriority(intpriority){

this.priority=priority;

}

/**

*根据要求来修改PCB的优先级

*/

publicvoidmodifyPriority(){

if(0

this.priority-=3;

}

return;

}

publicintgetCpuTime(){

returncpuTime;

}

publicvoidsetCpuTime(intcpuTime){

this.cpuTime=cpuTime;

}

/**

*根据要求修改CPU时间

*/

publicvoidmodifyCpuTime(){

this.cpuTime+=1;

}

publicintgetAllTime(){

returnallTime;

}

publicvoidsetAllTime(intallTime){

this.allTime=allTime;

}

/**

*根据要求修改PCB占用的时间片

*/

publicvoidmodifyAllTime(){

if(0

this.allTime-=1;

}

return;

}

publicintgetState(){

returnstate;

}

publicvoidsetState(intstate){

this.state=state;

}

/**

*根据要求修改PCB的状态

*/

publicvoidmidifyState(){

}

/**

*打印显示当前PCB的全部信息

*/

publicvoidshowStatus(){

System.out.println("PCB[id="+id+",priority="+priority

+",cpuTime="+cpuTime+",allTime="+allTime+",state="

+state+"]");

}

/**

*修改PCB的全部信息

*/

publicvoidmodify(){

if(0

this.allTime-=1;

}

this.cpuTime+=1;

if(0

this.priority-=3;

}

}

}

*创建PCB的数据结构

*

*@author*

*/

publicclassLineListNode{

privateLineListNodenode;

privateTelement;

/**

*创建空链表

*/

publicLineListNode(){

this.node=null;

this.element=null;

}

/**

*创建一个存储特定元素的线性表

*/

publicLineListNode(Telement){

this.node=null;

this.element=element;

}

/**

*返回当前结点点的下一个节点

*/

publicLineListNodegetNextNode(){

returnthis.node;

}

/**

*设置当前结点的下一个结点

*/

publicvoidsetNextNode(LineListNodenode){

this.node=node;

}

/**

*返回当前结点存储的数据元素

*/

publicTgetElement(){

returnthis.element;

}

/**

*设置当前结点存储的数据元素

*/

publicvoidsetElement(Telement){

this.element=element;

}

}

/**

*创建一个存储PCB用来线性链表,通过线性链表的相关操作来实现相应的功能

*

*@author*

*/

publicclassLineListPcb{

/**

*表示PCB线性表的长度

*/

privateintsize;

/**

*表示PCB线性表的头元素结点

*/

privateLineListNodeheadPcb;

/**

*表示PCB线性表尾元素结点

*/

privateLineListNodelastPcb;

/**

*创建一个空的PCB线性存储链表

*/

publicLineListPcb(){

this.size=0;

this.headPcb=null;

this.lastPcb=this.headPcb;

}

/**

*创建一个具有特定元素的PCB线性存储链表

*/

publicLineListPcb(LineListPcbllp){

this.size=llp.getSize();

this.headPcb=llp.getHeadPcb();

this.lastPcb=llp.getLastPcb();

}

/**

*从PCB线性表中的头部移除数据元素

*

*@paramelement

*/

publicvoidremoveElement(){

if(0==this.size){

return;

}

@SuppressWarnings("unused")

LineListNodetempNode=this.headPcb;

this.headPcb=this.headPcb.getNextNode();

tempNode=null;

this.size--;

/**

*这一段主要是为了处理移除数据元素后只剩下一个数据元素的时候的线性链表处理

*/

if(this.size==1){

this.headPcb.setNextNode(this.lastPcb);

this.lastPcb=this.headPcb;

this.lastPcb.setNextNode(null);

}

}

/**

*向PCB线性表中的添加数据元素

*

*@paramelement

*/

publicvoidaddElement(Telement){

LineListNodenewElement=newLineListNode(element);

if(this.headPcb==null){

/**

*头结点为空,表示链表中当前没有数据元素,说明头结点和尾结点指向同一内存空间

*/

this.headPcb=newElement;

/**

*新添加一个数据元素则仍然指向同一内存空间

*/

this.lastPcb=this.headPcb;

}else{

/**

*链表不为空,在这里要保证最后一个结点与新加入的结点连接在一起

*/

this.lastPcb.setNextNode(newElement);

this.lastPcb=newElement;

}

this.size++;

}

/**

*从PCB线性表中的头部移除数据元素,并将其添加到PCB线性表中的尾部

*/

publicvoidremoveFromHeadAddToLast(){

if(this.size<=1){

return;

}

LineListNodetempNode=this.headPcb;

this.headPcb=tempNode.getNextNode();

this.lastPcb.setNextNode(tempNode);

this.lastPcb=tempNode;

}

/**

*从PCB线性表中中的尾部移除数据元素,并将其添加到PCB的线性表中的头部

*/

publicvoidremoveFromLastAddToHead(){

if(0==this.size){

return;

}

LineListNodetempNode=this.lastPcb;

/**

*设置尾结点的以一个结点为空

*/

LineListNodelastSecondNode=this.headPcb;

/**

*@i=1表示指向PCB线性表的元素为线性表的第一个元素

*@i=this.size-1表示指向线性表的元素为线性表的末尾第二个数据元素

*/

for(inti=1;i

lastSecondNode=lastSecondNode.getNextNode();

}

lastSecondNode.setNextNode(null);

/**

*设置PCB线性表尾结点的下一个结点为头结点的下一个结点,头结点为为尾结点

*/

tempNode.setNextNode(this.headPcb.getNextNode());

this.headPcb=tempNode;

}

/**

*判断PCB线性表是否为空

*/

publicbooleanisEmpty(){

returnthis.size==0;

}

/**

*@returntheheadPcb

*/

publicLineListNodegetHeadPcb(){

returnthis.headPcb;

}

/**

*@returnthelastPcb

*/

publicLineListNodegetLastPcb(){

returnthis.lastPcb;

}

/**

*

*@returnPCB

*/

publicTgetPCB(){

returnthis.headPcb.getElement();

}

/**

*@paramheadPcb

*theheadPcbtoset

*/

publicvoidsetHeadPcb(LineListNodeheadPcb){

this.headPcb=headPcb;

}

/**

*@returnthesize

*/

publicintgetSize(){

returnthis.size;

}

/**

*@paramsize

*thesizetoset

*/

publicvoidsetSize(intsize){

this.size=size;

}

}

publicclassPCBProcess{

publicstaticvoidmain(String[]args){

PCB[]p={newPCB(0,9,0,3,1),newPCB(1,38,0,2,1),

newPCB(2,30,0,6,1),newPCB(3,29,0,3,1),

newPCB(4,0,0,4,1)};

LineListPcbllp=newLineListPcb();

for(inti=0;i

llp.addElement(p[i]);

}

while(true){

if(llp.getSize()==0){

break;

}

LineListNodelln=llp.getHeadPcb();

PCBpcb=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