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

  • 格式:doc
  • 大小:58.00 KB
  • 文档页数:17

下载文档原格式

  / 17
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

#include "iostream.h"

#include "stdlib.h"

#include "string.h"

struct PCB{

int id;

char name[10];

int size;

struct PCB *next;

};

struct PCB *running;

struct PCB *ready;

struct PCB *blocked;

struct PCB *q;

struct PCB *p;

int id=1;

int size;

char name[10];

////////////////////////////////////////////////////////////////////////////////////// struct DCT{ //设备

char name[10];

int busy;

PCB * occupied;

PCB * waiting;

struct DCT *next;

struct COCT* coct; //上级控制器

};

struct COCT{ //控制器

char name[10];

int busy;

PCB * occupied;

PCB * waiting;

struct COCT *next;

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

};

struct CHCT{ //通道

char name[10];

int busy;

PCB * occupied;

PCB * waiting;

struct CHCT *next;

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

struct DCT * dcts;

struct COCT *cocts;

struct CHCT *chcts;

void enqueue(int id,char *name,int size,struct PCB *head){ struct PCB *node=(struct PCB *)malloc(sizeof(struct PCB));

node->next=0;

node->id=id;

strcpy(node->name,name);

node->size=size;

struct PCB *tmp=head;

while(tmp->next!=0)

tmp=tmp->next;

tmp->next=node;

}

struct PCB * dequeue(struct PCB *head){

struct PCB * tmp=head->next;

if(head->next!=0){

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

tmp->next=0;

}

return(tmp);

}

void createProcess(){

printf("\nname: ");

scanf("%s",name);

printf("size: ");

scanf("%d",&size);

printf("\n");

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

if(running==0){

running=dequeue(ready);

}

}

void switchProcess(){

if(running!=0&&ready->next!=0)

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

running=dequeue(ready);

}

else

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

}

void blockProcess(){

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

}

}

void wakeupProcess(){

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

}

}

void terminateProcess(){ //结束进程

if(running==0){

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

}

else{

running=dequeue(ready);

}

}