设备管理实现.docx

上传人:b****8 文档编号:9197409 上传时间:2023-05-17 格式:DOCX 页数:42 大小:22.76KB
下载 相关 举报
设备管理实现.docx_第1页
第1页 / 共42页
设备管理实现.docx_第2页
第2页 / 共42页
设备管理实现.docx_第3页
第3页 / 共42页
设备管理实现.docx_第4页
第4页 / 共42页
设备管理实现.docx_第5页
第5页 / 共42页
设备管理实现.docx_第6页
第6页 / 共42页
设备管理实现.docx_第7页
第7页 / 共42页
设备管理实现.docx_第8页
第8页 / 共42页
设备管理实现.docx_第9页
第9页 / 共42页
设备管理实现.docx_第10页
第10页 / 共42页
设备管理实现.docx_第11页
第11页 / 共42页
设备管理实现.docx_第12页
第12页 / 共42页
设备管理实现.docx_第13页
第13页 / 共42页
设备管理实现.docx_第14页
第14页 / 共42页
设备管理实现.docx_第15页
第15页 / 共42页
设备管理实现.docx_第16页
第16页 / 共42页
设备管理实现.docx_第17页
第17页 / 共42页
设备管理实现.docx_第18页
第18页 / 共42页
设备管理实现.docx_第19页
第19页 / 共42页
设备管理实现.docx_第20页
第20页 / 共42页
亲,该文档总共42页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

设备管理实现.docx

《设备管理实现.docx》由会员分享,可在线阅读,更多相关《设备管理实现.docx(42页珍藏版)》请在冰点文库上搜索。

设备管理实现.docx

设备管理实现

第3部分、设备管理实现:

●基本要求:

在前面的实验基础上实现设备管理功能的模拟,主要包括通道和控制器的添加和删除,设备的添加、删除,设备的分配和回收。

●参考学时:

12学时

●实验提示:

1、

CPU

假定模拟系统中已有键盘、鼠标、打印机和显示器四个设备,另有三个控制器和两个通道,它们之间的控制关系如图所示:

2、设备管理子系统涉及到系统设备表(SDT)、通道控制表(CHCT)、控制器控制表(COCT)和设备控制表(DCT)来体现输入输出系统的四级结构和三级控制。

应实现上述数据结构来完成对外围设备的管理。

3、实现上述设备、控制器以及通道的层次关系,同时能够添加或删除新的设备、控制器或通道。

4、通过键盘命令模拟进程执行过程中提出的设备分配或释放请求,并为此请求分配或释放设备。

分配设备成功后可将进程状态调整为阻塞,释放设备后变为就绪状态。

5、分配设备时应如果该设备已被其它进程占用,则设备分配失败,请求进程进入阻塞状态,同时等待该设备的释放。

如果设备空闲,进程占用设备的同时还应提出申请控制器请求,直到与设备相关的通道都已申请成功为止。

6、设备、控制器或通道的释放应引起对应节点的等待队列中的第一个阻塞进程被唤醒。

如果被唤醒的进程还未完成申请操作,应继续执行上级节点的申请操作。

importjava.util.Vector;

importjava.io.*;

classProcess{

Page[]PageTable;

VectorPageQueue;

privateintsize;

privateintPagecount;

privateStringname;

doublevisit;

doublereplacement;

publicvoidsetPage(Page[]PageTable){

this.PageTable=newPage[PageTable.length];

for(inti=0;i

this.PageTable[i]=PageTable[i];

}

}

publicintgetPageBlock(intPageNum){

returnPageTable[PageNum].getBlockNum();

}

publicvoidsetSize(intsize){

this.size=size;

}

publicintgetSize(){

returnsize;

}

publicvoidsetPagecount(intPagecount){

this.Pagecount=Pagecount;

}

publicintgetPagecount(){

returnPagecount;

}

{

visit=0;

replacement=0;

}

publicProcess(){

}

publicProcess(Stringname){

this.name=name;

}

publicProcess(Stringname,intsize){

this(name);

this.size=size;

}

publicStringtoString(){

returnname;

}

}

classPage{

intflag;

intblockNum;

intwrited;//xiugaiwei

intaccessfield;//fangwenziduan

intswapsapce_blockno;//waicundizhi

intt;

{

blockNum=0;

writed=0;

accessfield=0;

t=0;

}

publicPage(){

flag=1;

swapsapce_blockno=-1;

}

publicPage(intflag,intswapsapce_blockno){

this.flag=flag;

this.swapsapce_blockno=swapsapce_blockno;

}

publicintgetBlockNum(){

returnblockNum;

}

publicintgetFlag(){

returnflag;

}

}

classIONode{

Stringname;

IONodenext;

Processprocess;

Vectorwaitinglist;

IONodeparent;

publicIONode(){}

publicIONode(Stringname){

this.name=name;

}

publicvoidsetNext(IONodenext){

this.next=next;

}

publicIONodegetNext(){

returnnext;

}

publicvoidsetParent(IONodeparent){

this.parent=parent;

}

publicStringtoString(){

returnname;

}

}

classCHCTextendsIONode{

Stringname;

CHCTnext;

Processprocess;

Vectorwaitinglist;

//CHCTparent;

publicCHCT(){}

publicCHCT(Stringname){

this.name=name;

}

publicvoidsetNext(CHCTnext){

this.next=next;

}

publicCHCTgetNext(){

returnnext;

}

publicvoidsetParent(CHCTparent){

this.parent=parent;

}

publicStringtoString(){

returnname;

}

}

classCOCTextendsIONode{

Stringname;

COCTnext;

Processprocess;

Vectorwaitinglist;

CHCTparent;

publicCOCT(){}

publicCOCT(Stringname){

this.name=name;

}

publicvoidsetNext(COCTnext){

this.next=next;

}

publicCOCTgetNext(){

returnnext;

}

publicvoidsetParent(CHCTparent){

this.parent=parent;

}

publicStringtoString(){

returnname;

}

}

classDCTextendsIONode{

Stringname;

DCTnext;

Processprocess;

Vectorwaitinglist;

COCTparent;

publicDCT(){}

publicDCT(Stringname){

this.name=name;

}

publicvoidsetNext(DCTnext){

this.next=next;

}

publicDCTgetNext(){

returnnext;

}

publicvoidsetParent(COCTparent){

this.parent=parent;

}

publicStringtoString(){

returnname;

}

}

classOS3{

publicstaticVectorready,blocked;

publicstaticProcessrunning;

publicstaticBufferedReaderbr;

staticint[][]a=newint[8][8];

staticint[][]d=newint[10][10];//置换空间

staticintcount=0;

staticCHCTchct=newCHCT();

staticCOCTcoct=newCOCT();

staticDCTdct=newDCT();

publicOS3(){

ready=newVector();

blocked=newVector();

br=newBufferedReader(newInputStreamReader(System.in));

for(inti=0;i

for(intj=0;j

if(Math.random()<0.5){

a[i][j]=0;

}

else{

a[i][j]=1;

}

}

}

for(inti=0;i

for(intj=0;j

if(Math.random()<0.5){

d[i][j]=0;

}

else{

d[i][j]=1;

}

}

}

InitProcess();//初始化进程

InitRelation();//初始化关系

//System.out.println("位示图----------------");

//print(a);

//System.out.println("置换空间--------------");

//print(d);

}

publicstaticvoidgo(){

while(true){

System.out.println("=======================================================================");

System.out.println("1:

进程创建");

System.out.println("2:

进程到时");

System.out.println("3:

进程阻塞");

System.out.println("4:

进程唤醒");

System.out.println("5:

进程结束");

System.out.println("6:

逻辑地址转换为物理地址");

System.out.println("7:

查看页表");

System.out.println("8:

显示位示图和置换空间");

System.out.println("9:

查看置换次数和缺页率");

System.out.println("10:

添加通道");

System.out.println("11:

添加控制器");

System.out.println("12:

添加设备");

System.out.println("13:

删除通道");

System.out.println("14:

删除控制器");

System.out.println("15:

删除设备");

System.out.println("16:

分配设备");

System.out.println("17:

释放设备");

System.out.println("18:

显示设备分配状态");

System.out.println("0:

退出-->");

try{

inti=Integer.parseInt(br.readLine());

switch(i){

case0:

System.exit(0);

case1:

createNewProcess();

break;

case2:

switchCurrentProcess();

break;

case3:

blockCurrentProcess();

break;

case4:

wakeupBlockedProcess();

break;

case5:

terminateCurrentProcess();

break;

case6:

transform();

break;

case7:

showPage();

break;

case8:

System.out.println("位示图----------------");

print(a);

System.out.println("置换空间--------------");

print(d);

break;

case9:

look();

break;

case10:

addChannel();

break;

case11:

addController();

break;

case12:

addDeviced();

break;

case13:

deleteChannel();//删除通道

break;

case14:

deleteController();

break;

case15:

deleteDeviced();

break;

case16:

allocateDeviced();

break;

case17:

try{

System.out.println("设备名称:

");

Stringname=br.readLine();

recoverDeviced(name);

}catch(Exceptione){

System.out.println(e);

}

break;

case18:

showDevicedAllocate();

break;

}

}

catch(Exceptione){

System.out.println(e);

}

System.out.println("执行进程:

");

if(running!

=null){

System.out.println(""+running+"("+running.getSize()+")");

}

else{

System.out.println("none");

}

//System.out.println("执行进程:

"+(running==null?

"none":

running+"("+running.getSize()+")"));

System.out.println("就绪进程:

");

printList(ready);

System.out.println("阻塞进程:

");

printList(blocked);

}

}

publicstaticvoidprintList(Vectorv){

for(inti=0;i

//System.out.print(v.elementAt(i)+"\t");

System.out.println(""+v.elementAt(i)+"("+(v.elementAt(i)).getSize()+")"+"\t");

}

}

publicstaticCHCTfindChannel(Stringname1){

CHCTc=chct;

while(c.getNext()!

=null){

if((c.getNext().name).equals(name1)){

returnc.getNext();

}

c=c.getNext();

}

returnnull;

}

publicstaticCOCTfindController(Stringname1){

COCTc=coct;

while(c.getNext()!

=null){

if((c.getNext().name).equals(name1)){

returnc.getNext();

}

c=c.getNext();

}

returnnull;

}

publicstaticDCTfindDeviced(Stringname1){

DCTd=dct;

while(d.getNext()!

=null){

if((d.getNext().name).equals(name1)){

returnd.getNext();

}

d=d.getNext();

}

returnnull;

}

publicstaticvoidadd(Stringname1,Stringname2,inttype){

if(type==1){

CHCTtmp=newCHCT(name1);

CHCTc=chct;

while(c.getNext()!

=null){

//System.out.println("c============"+c.getNext());

c=c.getNext();

}

//System.out.println("c=====CHCT"+c);

c.setNext(tmp);

tmp.process=null;

tmp.waitinglist=newVector();

tmp.parent=null;

}

if(type==2){

COCTtmp=newCOCT(name1);

COCTp=coct;

CHCTq=findChannel(name2);

while(p.getNext()!

=null){

//System.out.println("p========="+p.getNext());

p=p.getNext();

}

//System.out.println("p=====COCT-----"+p);

p.setNext(tmp);

tmp.process=null;

tmp.waitinglist=newVector();

if(q!

=null){

tmp.parent=q;

}

else{

System.out.println("nofound");

}

}

if(type==3){

DCTtmp=newDCT(name1);

DCTd=dct;

COCTc=findController(name2);

//System.out.println("is4ma");

if(c==null){

System.out.println("error");

return;

}

while(d.getNext()!

=null){

//System.out.println(d);

//System.out.println("d==============="+d.getNext());

d=d.getNext();

}

//System.out.println("d=====dct==="+d);

d.setNext(tmp);

tmp.process=null;

tmp.waitinglist=newVector();

if(c!

=null){

tmp.parent=c;

}

else{

System.out.println("nofound");

}

}

}

publicstaticvoidaddChannel(){

try{

System.out.println("输入通道名:

");

Stringname1=br.readLine();

add(name1,"",1);

}

catch(Exceptione){

System.out.println(e);

}

}

publicstaticvoidaddController(){

try{

System.out.println("输入控制器名:

");

Stringname1=br.readLine();

System.out.println("输入通道名:

");

Stringname2=br.readLine();

add(nam

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

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2