完整word版操作系统课程设计设备管理实现 源代码.docx

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

完整word版操作系统课程设计设备管理实现 源代码.docx

《完整word版操作系统课程设计设备管理实现 源代码.docx》由会员分享,可在线阅读,更多相关《完整word版操作系统课程设计设备管理实现 源代码.docx(22页珍藏版)》请在冰点文库上搜索。

完整word版操作系统课程设计设备管理实现 源代码.docx

完整word版操作系统课程设计设备管理实现源代码

#include

#include"iostream.h"

#include"stdlib.h"

#include"string.h"

structPCB{

intid;

charname[10];

intsize;

structPCB*next;

};

structPCB*running;

structPCB*ready;

structPCB*blocked;

structPCB*q;

structPCB*p;

intid=1;

intsize;

charname[10];

//////////////////////////////////////////////////////////////////////////////////////

structDCT{//设备

charname[10];

intbusy;

PCB*occupied;

PCB*waiting;

structDCT*next;

structCOCT*coct;//上级控制器

};

structCOCT{//控制器

charname[10];

intbusy;

PCB*occupied;

PCB*waiting;

structCOCT*next;

structCHCT*chct;//控制器的上级通道

};

structCHCT{//通道

charname[10];

intbusy;

PCB*occupied;

PCB*waiting;

structCHCT*next;

};

//////////////////////////////////////////////////////////////////////////////////////

structDCT*dcts;

structCOCT*cocts;

structCHCT*chcts;

voidenqueue(intid,char*name,intsize,structPCB*head){

structPCB*node=(structPCB*)malloc(sizeof(structPCB));

node->next=0;

node->id=id;

strcpy(node->name,name);

node->size=size;

structPCB*tmp=head;

while(tmp->next!

=0)

tmp=tmp->next;

tmp->next=node;

}

structPCB*dequeue(structPCB*head){

structPCB*tmp=head->next;

if(head->next!

=0){

head->next=head->next->next;

tmp->next=0;

}

return(tmp);

}

voidcreateProcess(){

printf("\nname:

");

scanf("%s",name);

printf("size:

");

scanf("%d",&size);

printf("\n");

enqueue(id++,name,size,ready);

if(running==0){

running=dequeue(ready);

}

}

voidswitchProcess(){

if(running!

=0&&ready->next!

=0)

{

enqueue(running->id,running->name,running->size,ready);

running=dequeue(ready);

}

else

printf("没有可切换的进程\n");

}

voidblockProcess(){

if(running==0)

printf("没有可阻塞的进程\n");

else

{

enqueue(running->id,running->name,running->size,blocked);

running=0;

if(ready->next==0)

printf("没有可执行的进程\n");

else

running=dequeue(ready);

}

}

voidwakeupProcess(){

if(blocked->next==0)

printf("没有可激活的进程");

else

{

enqueue(blocked->next->id,blocked->next->name,blocked->next->size,ready);

dequeue(blocked);

if(running==0)

running=dequeue(ready);

}

}

voidterminateProcess(){//结束进程

if(running==0){

printf("没有需要结束的进程\n");

}

else{

running=dequeue(ready);

}

}

voiddisplayProcessstatus(){

printf("--------就绪态--------\n");

if(ready->next==0)

printf("当前没有进程在该状态\n");

if(ready->next!

=0)

{

q=ready->next;

while(ready->next!

=0)

{

printf("%s",ready->next->name);

printf("%d\n",ready->next->size);

ready->next=ready->next->next;

}

ready->next=q;

}

printf("--------执行状态--------\n");

if(running==0)printf("当前没有进程在该状态\n");

if(running!

=0)

{

printf("%s",running->name);

printf("%d\n",running->size);

}

printf("--------阻塞状态--------\n");

if(blocked->next==0)printf("当前没有进程在该状态\n\n");

if(blocked->next!

=0)

{

p=blocked->next;

while(blocked->next!

=0)

{

printf("%s",blocked->next->name);

printf("%d\n",blocked->next->size);

blocked->next=blocked->next->next;

}

blocked->next=p;

}

}

//////////////////////////////////////////////////////////////////////////////////

structDCT*findDCT(charname[])//设备分配时找到要添加的设备

{

structDCT*temp=dcts;

while(temp->next!

=NULL)

{

temp=temp->next;

if(strcmp(temp->name,name)==0)

returntemp;

}

returnNULL;

}

structCHCT*findChannel(charname[])

{

structCHCT*temp=chcts;

while(temp->next!

=NULL)

{

temp=temp->next;

if(strcmp(temp->name,name)==0)

returntemp;

}

returnNULL;

}

structCOCT*findController(charname[])

{

structCOCT*temp=cocts;

while(temp->next!

=NULL)

{

temp=temp->next;

if(strcmp(temp->name,name)==0)

returntemp;

}

returnNULL;

}

voidaddProcesstoWaiting(structPCB*waiting,structPCB*p)//进入进程等待队列

{

structPCB*temp=waiting;

while(temp->next!

=NULL)

{

temp=temp->next;

}

//temp->next=p;

//+++++++++++++++++++++++++++++++++++++++++++++++++

temp->next=newstructPCB;

temp->next->id=p->id;

strcpy(temp->next->name,p->name);

temp->next->size=p->size;

temp->next->next=NULL;

//++++++++++++++++++++++++++++++++++++++++++++++++++

}

voidadd(structPCB*head,structPCB*node){//入队列

structPCB*tmp=head;

while(tmp->next!

=0)

tmp=tmp->next;

tmp->next=node;

}

structPCB*getFirst(structPCB*head){//获得队列里的第一个进程

returnhead->next;

}

voidallocateCHCT(structCHCT*chct,PCB*p)//分配CHCT

{

if(chct->occupied!

=0)

{

printf("不能分配通道\n");

addProcesstoWaiting(chct->waiting,p);

}

else

{

chct->occupied=p;

printf("分配成功!

\n");

}

add(blocked,p);

if(ready!

=0)

running=dequeue(ready);

else

running=0;

}

//**************************************************

voidallocateCOCT(structCOCT*coct,PCB*p)

{

if(coct->occupied!

=0){

printf("不能分配控制器\n");

addProcesstoWaiting(coct->waiting,p);

add(blocked,p);

if(ready!

=0)

running=dequeue(ready);

else

running=0;

return;

}else{

coct->occupied=p;

allocateCHCT(coct->chct,p);

}

}

voidallocateDCT(){

charnameDCT[10];

printf("请输入设备名称:

");

scanf("%s",nameDCT);

structDCT*dct=findDCT(nameDCT);

structPCB*p=running;

if(dct!

=NULL&&p!

=NULL)

{

if(dct->occupied!

=0){

printf("不能分配设备\n");

addProcesstoWaiting(dct->waiting,p);

add(blocked,p);

if(ready!

=0)

running=dequeue(ready);

else

running=0;

return;

}else{

dct->occupied=p;

allocateCOCT(dct->coct,p);

//++++++++++++++++++++++++++++

/*add(blocked,p);

if(ready!

=0)

running=dequeue(ready);

else

running=0;

return;*/

//+++++++++++++++++++++++++++++

}

}

else

printf("发生错误!

\n");

}

voidreleaseCHCT(char*name,structCHCT*chct,structPCB*p)//?

?

?

?

?

?

{

if(p!

=NULL)

addProcesstoWaiting(chct->waiting,p);

if(strcmp(name,chct->occupied->name)==0)

{

if(chct->waiting->next!

=NULL)

{

chct->occupied=dequeue(chct->waiting);

}

else

{

chct->occupied=NULL;

}

}

}

voidreleaseCOCT(char*name,structCOCT*coct,structPCB*p)

{

if(p!

=NULL)

addProcesstoWaiting(coct->waiting,p);

if(strcmp(name,coct->occupied->name)==0)

{

if(coct->waiting->next!

=NULL)

{

coct->occupied=dequeue(coct->waiting);

}

else

{

coct->occupied=NULL;

}

releaseCHCT(name,coct->chct,coct->occupied);

}

}

voidreleaseDCT()

{

charnameDCT[10];

printf("请输入要释放的设备名称:

\n");

scanf("%s",nameDCT);

charnameP[10];

printf("请输入要释放的进程名称:

\n");

scanf("%s",nameP);

structDCT*temp=findDCT(nameDCT);

if(strcmp(temp->occupied->name,nameP)==0)

{

if(temp->waiting->next!

=NULL)

{

temp->occupied=dequeue(temp->waiting);

}

else

{

temp->occupied=NULL;

}

releaseCOCT(nameP,temp->coct,temp->occupied);

}

else

{

printf("没有对应的设备和进程!

");

}

}

voidaddChannel(charname[]){

structCHCT*temp=(structCHCT*)malloc(sizeof(structCHCT));

strcpy(temp->name,name);

temp->next=0;

temp->busy=0;

temp->waiting=newstructPCB;

temp->waiting->next=NULL;

//temp->waiting=0;

temp->occupied=0;

structCHCT*head=chcts;//进入了chcts队列

while(head->next!

=0)

head=head->next;

head->next=temp;

}

voidaddController(char*name,structCHCT*chct){//增加控制器

structCOCT*temp=(structCOCT*)malloc(sizeof(structCOCT));

strcpy(temp->name,name);

temp->next=0;

temp->busy=0;

temp->waiting=newstructPCB;

temp->waiting->next=NULL;

//temp->waiting=0;//+

temp->occupied=0;

temp->chct=chct;

structCOCT*head=cocts;//进入了cocts队列

while(head->next!

=0)

head=head->next;

head->next=temp;

}

voidaddDevice(char*name,structCOCT*coct){//增加设备

structDCT*temp=(structDCT*)malloc(sizeof(structDCT));

strcpy(temp->name,name);

temp->next=0;

temp->busy=0;

temp->waiting=newstructPCB;

temp->waiting->next=NULL;

//temp->waiting=0;

temp->occupied=0;

temp->coct=coct;

structDCT*head=dcts;

while(head->next!

=0)

head=head->next;

head->next=temp;

}

//添加设备++++++++++++++++++++++++++++++++++

voidadd_dct(){

charnewDCT[10];

printf("请输入新设备的名字:

\n");

scanf("%s",newDCT);

charnewCOCT[10];

printf("请输入要添加到的控制器的名字:

\n");

scanf("%s",newCOCT);

addDevice(newDCT,findController(newCOCT));

}

//添加控制器

voidadd_coct(){

charnewCOCT[10];

printf("请输入新控制器的名字:

\n");

scanf("%s",newCOCT);

charnewCHCT[10];

printf("请输入要添加到的通道的名字:

\n");

scanf("%s",newCHCT);

addController(newCOCT,findChannel(newCHCT));

}

//添加通道

voidadd_chct(){

charnewCHCT[10];

printf("请输入新的通道的名字:

\n");

scanf("%s",newCHCT);

addChannel(newCHCT);

}

//++++++++++++++++++++++++++++++++++

//+++++++++++++++++删除操作++++++++++++++++++++

//删除设备

voiddeleteDCT(charnameDCT[]){

//charnameDCT[10];

//inti=0;

//printf("请输入要删除DCT的名字:

");

//scanf("%s",nameDCT);

structDCT*temp=findDCT(nameDCT);

structDCT*head=dcts;

if(temp==NULL){

printf("没有对应的设备!

\n");

return;

}

else

while(head->next!

=0)

{

if(strcmp(temp->name,head->next->name)==0)

{

if(temp->occupied!

=NULL)

printf("此设备现在正在使用不能删除\n");

else

head->next=head->next->next;

//i++;

break;

}

else

head=head->next;

}

}

//删除控制器

voiddeleteCOCT(charnameCOCT[]){

structCOCT*temp=findController(nameCOCT);

structCOCT*head=cocts;

if(temp==NULL){

printf("没有对应的控制器\n");

return;

}

else

while(head->next!

=0)

{

if(strcmp(temp->name,head->next->name)==0){

if(temp->occupied!

=NULL)

printf("此控制器现在正在使用不能删除\n");

else{

//deleteDCT(temp->);

head->next=head->next->next;

}

break;

}

head=head->next;

}

}

//删除通道

voiddeleteCHCT(charnameCHCT[]){

structCHCT*temp=findChannel(nameCHCT);

structCHCT*head=chcts;

if(temp==NULL){

printf("没有对应的通道\n");

return;

}

else

while(head->next!

=0)

{

if(strcm

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

当前位置:首页 > 工程科技

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

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