操作系统设备管理代码

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

实验报告

课程名称操作系统

实验项目设备管理

专业计算机科学与技术班级计科4班姓名秦宇学号******** 指导教师于桂玲实验成绩

2012年6月13日

实验5 设备管理

一、实验目的

理解设备管理的概念和任务,掌握独占设备的分配、回收等主要算法的原理并编程实现。

二、实验内容

编写程序实现对独占设备的分配与回收的模拟。

三、实验要求

1、实现设备分配、回收、显示系统中设备信息的功能。

2、通过设备类表和设备表记录系统中设备信息、以便进行设备分配。

3、设备类表记录系统中全部设备的情况,每个设备类占一个表目,设备类表的数据结构如表1所示。

4、为每一个设备配置一张设备控制表,用于记录本设备的情况。设备控制表的数据结构如图2所示。

4、程序中建立分配设备和回收设备函数。

5、设系统有3类设备,每类设备的设备数分别为2、3、4。

6、要求键盘输入作业名、作业所需设备类和设备相对号。

程序代码:

#include "iostream"

#include "string"

#include "vector"

using namespace std;

typedef struct node

{

string ID; //进程名

string equipment; //申请的设备名

struct node *next;

}PCB;

typedef struct

{

string channelID; //通道标识符

bool state; //通道状态

PCB *use; //正在使用该通道的进程 PCB *blockqueue; //阻塞队首

}CHCT;

typedef struct

{

string controllerID; //控制器标示

bool state; //控制器状态

CHCT *front; //通道表指针

PCB *use; //正在使用该控制器的进程 PCB *blockqueue; //阻塞队首

}COCT;

typedef struct

{

char type; //设备类型

string equipmentID; //设备名

bool state; //设备状态

COCT *front; //控制器指针

PCB *use; //正在使用该设备的进程 PCB *blockqueue; //阻塞队首

}DCT;

typedef struct

{

char type; //设备类型

string equipmentID; //设备名

DCT *dct; //设备的DCT

}SDT;

DCT *k=new DCT; //键盘的DCT

DCT *m=new DCT;

DCT *p=new DCT;

DCT *t=new DCT;

COCT *c1=new COCT;

COCT *c2=new COCT;

COCT *c3=new COCT;

CHCT *h1=new CHCT;

CHCT *h2=new CHCT;

CHCT *h3=new CHCT;

int check(char cmd)

{

switch(cmd)

{

case 'c': //申请

return 1;

case 'C':

return 1;

case 'd': //删除

return 2;

case 'D':

return 2;

case 'a': //添加

return 3;

case 'A':

return 3;

case 'f': //释放

return 4;

case 'F':

return 4;

case 'q':

return -1;

case 'Q':

return -1;

case 'p':

return 5;

case 'P':

return 5;

default:

return 0;

}

}

void init(vector &SDT_table)

{

SDT_table[0].equipmentID="M";

SDT_table[0].type='2'; //鼠标是第二类设备 SDT_table[0].dct=m; //设备的DCT表位置

SDT_table[1].equipmentID="K";

SDT_table[1].type='1';

SDT_table[1].dct=k;

SDT_table[2].equipmentID="P"; SDT_table[2].type='3';

SDT_table[2].dct=p;

SDT_table[3].equipmentID="T"; SDT_table[3].type='4';

SDT_table[3].dct=t;

h1->blockqueue=NULL;

h1->channelID="通道1";

h1->state=true;

h1->use=NULL;

h2->blockqueue=NULL;

h2->channelID="通道2";

h2->state=true;

h2->use=NULL;

c1->blockqueue=NULL;

c1->controllerID="控制器1"; c1->state=true;

c1->front=h1;

c1->use=NULL;

c2->blockqueue=NULL;

c2->controllerID="控制器2"; c2->state=true;

c2->front=h1;

c2->use=NULL;

c3->blockqueue=NULL;

c3->controllerID="控制器3"; c3->state=true;

c3->front=h2;

c3->use=NULL;

k->blockqueue=NULL;

k->equipmentID="K";

k->state=true; //可用

k->type='1';

k->front=c1;

k->use=NULL;

m->blockqueue=NULL;

m->equipmentID="M";

m->state=true;

m->type='2';

m->front=c1;

m->use=NULL;

p->blockqueue=NULL;

p->equipmentID="P";

p->state=true;

相关文档
最新文档