模拟操作系统进程优先级调度Word格式.docx

上传人:b****3 文档编号:18518697 上传时间:2022-12-18 格式:DOCX 页数:13 大小:18.52KB
下载 相关 举报
模拟操作系统进程优先级调度Word格式.docx_第1页
第1页 / 共13页
模拟操作系统进程优先级调度Word格式.docx_第2页
第2页 / 共13页
模拟操作系统进程优先级调度Word格式.docx_第3页
第3页 / 共13页
模拟操作系统进程优先级调度Word格式.docx_第4页
第4页 / 共13页
模拟操作系统进程优先级调度Word格式.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

模拟操作系统进程优先级调度Word格式.docx

《模拟操作系统进程优先级调度Word格式.docx》由会员分享,可在线阅读,更多相关《模拟操作系统进程优先级调度Word格式.docx(13页珍藏版)》请在冰豆网上搜索。

模拟操作系统进程优先级调度Word格式.docx

取的修改

*/publicPCB(){

}

/**

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

*@param

id

priority

cpuTime

allTime

state

publicPCB(int

id,intpriority,intcpuTime,intallTime,int

state){

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){this.priority-=3;

returnpublicintgetCpuTime(){returncpuTime;

publicvoidsetCpuTime(intcpuTime){this.cpuTime=cpuTime;

*根据要求修改CPU时间

*/publicvoidmodifyCpuTime(){this.cpuTime+=1;

publicintgetAllTime(){returnallTime;

publicvoidsetAllTime(intallTime){this.allTime=allTime;

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

*/publicvoidmodifyAllTime(){if(0<

this.allTime){this.allTime-=1;

return;

publicintgetState(){returnstate;

publicvoidsetState(intstate){this.state=state;

*根据要求修改PCB的状态*/

publicvoidmidifyState(){

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

*/publicvoidshowStatus(){

System.out.println("

PCB[id="

+id+"

priority="

+"

cpuTime="

+cpuTime+"

allTime="

state="

+state+"

]"

);

*修改PCB的全部信息

publicvoidmodify(){

if(0<

this.allTime){

this.allTime-=1;

this.cpuTime+=1;

this.priority){

this.priority-=3;

//采用链表存储

创建PCB的数据结构

*@author摆渡恋人

*/publicclassLineListNode<

T>

{privateLineListNode<

node;

privateTelement;

创建空链表

*/publicLineListNode(){

this.node=null;

this.element=null;

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

*/publicLineListNode(Telement){this.node=null;

this.element=element;

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

*/publicLineListNode<

getNextNode(){returnthis.node;

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

*/publicvoidsetNextNode(LineListNode<

node){this.node=node;

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

*/publicTgetElement(){returnthis.element;

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

publicvoidsetElement(Telement){this.element=element;

packagexiao.zhang.backup;

importxiao.zhang.osa.LineListNode;

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

现相应的功能

*@authorXiaoZhang

*/publicclassLineListPcb<

PCB>

{/**

*表示PCB线性表的长度

*/privateintsize;

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

*/privateLineListNode<

headPcb;

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

privateLineListNode<

lastPcb;

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

*/publicLineListPcb(){

this.size=0;

this.headPcb=null;

this.lastPcb=this.headPcb;

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

*/publicLineListPcb(LineListPcb<

llp){this.size=llp.getSize();

this.headPcb=llp.getHeadPcb();

this.lastPcb=llp.getLastPcb();

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

@paramelement

publicvoidremoveElement(){if(0==this.size){

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

if(this.size==1){

//this.headPcb.setNextNode(this.lastPcb);

//this.lastPcb=this.headPcb;

//this.lastPcb.setNextNode(null);

this.size--;

LineListNode<

tempNode=this.headPcb;

this.headPcb=tempNode.getNextNode();

tempNode=null;

*@paramelement

*/publicvoidaddElement(PCBelement){

newElement=new

(element);

if(this.headPcb==null){/**

*头结点为空,表示链表中当前没有数据元素,说明头结

点和尾结点指向同一内存空间

this.headPcb=newElement;

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

}else{

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

点连接在一起

PCB线性

PCB的

this.lastPcb.setNextNode(newElement);

this.lastPcb=newElement;

this.size++;

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

表中的尾部

publicvoidremoveFromHeadAddToLast(){

if(this.size<

=1){return;

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

this.lastPcb.setNextNode(tempNode);

this.lastPcb=tempNode;

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

publicvoidremoveFromLastAddToHead(){if(0==this.size){return;

tempNode=this.lastPcb;

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

lastSecondNode=this.headPcb;

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

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

二个数据元素

for(inti=1;

i<

this.size-1;

i++){

lastSecondNode=lastSecondNode.getNextNode();

}lastSecondNode.setNextNode(null);

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

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

this.headPcb=tempNode;

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

*并根据线性表中的数据元素的优先级从高到低的顺序将头数

据元素放置在合适的位置

*//**

*@基本思想是:

*1.通过获得头数据元素,并且得到其优先级

*2.获得链表的下一个数据元素tempNode,并得到其优先级

*3.通过比较头数据元素的优先级priority和通过线性表获得的数据元素的优先级tempPrority的比较

*3.1如果大于等于则将头数据元素插入在当前(tempNode)的数据元素的后面

*3.2如果小于则继续2-3步

publicvoidinsertPCBByPrority(){

headNode=this.headPcb;

intcurrentPrority=((xiao.zhang.osa.PCB)headNode.getElement())

.getPriority();

nextNode=headNode.getNextNode();

intnextPrority=((xiao.zhang.osa.PCB)nextNode.getElement())

if(currentPrority>

nextPrority){

this.headPcb=nextNode;

for(inti=2;

this.size;

i++){LineListNode<

nextNextNode=

nextNode.getNextNode();

intnextNextPrority=((xiao.zhang.osa.PCB)nextNextNode

.getElement()).getPriority();

if(currentPrority<

nextPrority

&

currentPrority>

nextNextPrority){nextNode.setNextNode(headNode);

headNode.setNextNode(nextNextNode);

return;

nextNode=nextNextNode;

//nextNode.setNextNode(nextNextNode);

nextPrority=nextNextPrority;

this.lastPcb.setNextNode(headNode);

headNode.setNextNode(null);

this.lastPcb=headNode;

*判断PCB线性表是否为空

publicbooleanisEmpty(){returnthis.size==0;

*@returntheheadPcb

getHeadPcb(){returnthis.headPcb;

*@returnthelastPcb

getLastPcb(){returnthis.lastPcb;

*@returnPCB

publicPCBgetPCB(){

returnthis.headPcb.getElement();

@paramheadPcb

theheadPcbtoset

*/publicvoidsetHeadPcb(LineListNode<

headPcb){this.headPcb=headPcb;

*@returnthesize

publicintgetSize(){returnthis.size;

*@paramsize

*thesizetoset

publicvoid

setSize(intsize){

this.size=

size;

主方法:

publicclassPCBProcess{

进入

*@paramp

*@paramllp

privatestaticvoidcomeLineList(PCB[]p,LineListPcb<

llp){

for(inti=0;

p.length;

intminIndex=i;

for(intj=i+1;

j<

j++){

if(p[minIndex].getPriority()<

p[j].getPriority()){

*在这里也可以直接对PCB线性链表添加数据元素

minIndex=j;

break;

if(minIndex!

=i){

PCBtemp=p[minIndex];

p[minIndex]=p[i];

p[i]=temp;

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

llp.addElement(p[i]);

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)};

*进行优先级的调度算法

LineListPcb<

llp=newLineListPcb<

();

comeLineList(p,llp);

*业务处理流程

while(true){

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

lln=llp.getHeadPcb();

PCBpcb=lln.getElement();

System.out.print("

进程占有时间片前状态"

+pcb.getId());

pcb.showStatus();

pcb.modify();

进程占有时间片后状态"

if(0!

=pcb.getAllTime()){

System.out.println();

llp.insertPCBByPrority();

System.out.println(

“八**********************"

I!

程"

+pcb.getId()+"

获得执行,并且移除就绪队列

八**********************"

llp.removeElement();

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

当前位置:首页 > 经管营销 > 人力资源管理

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

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