#include <iostream>
#include <cstdlib>
#include <iomanip>
#include "conio.h"
using namespace std;
/*定义结构体*/
int bitmap[8][8];
typedef struct PCB {
char name[20];
int size;
int *page_table;
struct PCB * next;
}PCB;
PCB *ready,*blocked,*running,*finished;
typedef struct Node{
char name[10]; //名称
struct PCB *process; //占用该节点的进程
struct PCB *waitinglist; //等待该节点的进程队列
struct Node *next; //下一个节点
struct Node *parent; //父节点
}NODE;
NODE *CHCT; //通道队列头节点
NODE *COCT; //控制器队列头节点
NODE *DCT;
PCB * out(PCB *head);
void add(PCB *head, PCB *process);
void initFacility();
void addCHCT();
void addCOCT();
void addDCT();
void deleteCHCT();
void deleteCOCT();
void deleteDCT();
void allotFacility();
void releaseFacility();
void printFacility();
void setmap(int *bitmap ,int row ,int rank);
void printmap(int *bitmap ,int row ,int rank);
int getbit(int *bitmap ,int row ,int rank);
void address_translate ();
void exitmap(int *bitmap);
void printpage_table();
void create();
void torun();
void timeout();
void wakeup();
void block();
void ending();
void show();
void help();
void help2_1();
void help2_2();
void init();
void main() {
char ch,a,b;
init();
initFacility();
help();
cout<<endl;
setmap(*bitmap,8,8);
cout<<"Bit Map:"<<endl;
printmap(*bitmap,8,8);
cout<<endl;
cout<<" Please input: ";
cin>>ch;
while(ch != 'q') {
switch(ch) {
case 'h':
case 'H': help(); break;
case 'c':
case 'C': create(); show(); break;
case 'b':
case 'B': block(); show(); break;
case 'W':
case 'w': wakeup(); show(); break;
case 'R':
case 'r': torun(); show(); break;
case 'S':
case 's': show(); break;
case 'E':
case 'e': ending(); show(); break;
case 'T':
case 't': timeout(); show(); break;
case '1': printmap(*bitmap,8,8); break;
case '2': printpage_table(); break;
case '3': address_translate();break;
case '4': help2_1();
cout<<"选择:";
cin>>a;
while(a != '0'){
switch(a) {
case '1': addCHCT();printFacility();break;
case '2': addCOCT();printFacility();break;
case '3': addDCT();printFacility();break;
}
cout<<endl;
help2_1();
cout<<"选择:";
cin>>a;
}
break;
case '5':help2_2();
cout<<"选择:";
cin>>a;
while(a != '0'){
switch(a) {
case '1': deleteCHCT();printFacility();break;
case '2': deleteCOCT();printFacility();break;
case '3': deleteDCT();printFacility();break;
}
cout<<endl;
help2_2();
cout<<"选择:";
cin>>a;
}
break;
case '6':allotFacility();printFacility();break;
case '7':releaseFacility();printFacility();break;
case '8':printFacility();break;
case 'Q':
case 'q': cout<<"Quit the PCB"<<endl; break;
default:cout<<" Input error "<<endl;
}
cout<<endl;
cout<<" Please input: ";
cin>>ch;
}
}
void initFacility() { //初始化设备
CHCT = (NODE*)malloc(sizeof(NODE));
CHCT->next = NULL;
COCT = (NODE*)malloc(sizeof(NODE));
CHCT->next = NULL;
DCT = (NODE*)malloc(sizeof(NODE));
DCT->next = NULL;
NODE *a,*b, *d,*e,*f, *j,*k,*l,*m; //a,b两个通道; d,e,f三个控制器;j,k,l,m四个设备
a = (NODE*)malloc(sizeof(NODE));
b = (NODE*)malloc(sizeof(NODE));
strcpy(a->name ,"CHCT1");
a->parent = NULL;
a->process = NULL;
a->waitinglist = NULL;
strcpy(b->name, "CHCT2");
b->parent = NULL;
b->process = NULL;
b->waitinglist = NULL;
a->next = b;
b->next = NULL;
CHCT->next = a;
d = (NODE*)malloc(sizeof(NODE));
e = (NODE*)malloc(sizeof(NODE));
f = (NODE*)malloc(sizeof(NODE));
strcpy(d->name ,"COCT1");
d->parent = a;
d->process = NULL;
d->waitinglist = NULL;
strcpy(e->name,"COCT2");
e->parent = a;
e->process = NULL;
e->waitinglist = NULL;
strcpy(f->name ,"COCT3");
f->parent = b;
f->process = NULL;
f->waitinglist = NULL;
d->next = e;
e->next = f;
f->next =NULL;
COCT->next = d;
j = (NODE*)malloc(sizeof(NODE));
k = (NODE*)malloc(sizeof(NODE));
l = (NODE*)malloc(sizeof(NODE));
m = (NODE*)malloc(sizeof(NODE));
strcpy(j->name ,"1");
j->parent = d;
j->process = NULL;
j->waitinglist = NULL;
strcpy(k->name, "2");
k->parent = d;
k->process = NULL;
k->waitinglist = NULL;
strcpy(l->name ,"3");
l->parent = e;
l->process = NULL;
l->waitinglist = NULL;
strcpy(m->name ,"4");
m->parent = f;
m->process = NULL;
m->waitinglist = NULL;
DCT->next = j;
j->next = k;
k->next = l;
l->next = m;
m->next = NULL;
}
void printFacility() { //显示设备表
NODE *r,*s,*t;
r = CHCT->next;
s = COCT->next;
t = DCT->next;
while(r) {
cout<<setw(6)<<r->name;
if(r->process) {
cout<<" P:";
cout<<"—"<<r->process->name;
}
if(r->waitinglist) {
PCB *p;
p = r->waitinglist;
cout<<" W:";
while(p != NULL) {
cout<<"—"<<p->name;
p = p->next;
}
}
cout<<endl;
if(s != NULL) {
while(s->parent == r) {
cout<<setw(22)<<s->name;
if(s->process) {
cout<<" P:";
cout<<"—"<<s->process->name;
}
if(s->waitinglist) {
PCB *q;
q = s->waitinglist;
cout<<" W:";
while(q != NULL) {
cout<<"—"<<q->name;
q = q->next;
}
}
cout<<endl;
if(t) {
while(t->parent == s) {
cout<<setw(38)<<t->name;
if(t->process) {
cout<<" P:";
cout<<"—"<<t->process->name;
}
if(t->waitinglist) {
PCB *o;
o = t->waitinglist;
cout<<" W:";
while(o != NULL) {
cout<<"—"<<o->name;
o = o->next;
}
}
cout<<endl;
t = t->next;
if(t == NULL)
break;
}
}
s = s->next;
if(s == NULL)
break;
}
}
cout<<"————————————————————"<<endl;
r = r->next;
}
}
void addCHCT() { //添加通道
NODE *p, *q;
q = CHCT;
p = (NODE*)malloc(sizeof(NODE));
cout<<"请输入通道名称:";
cin>>p->name;
p->next = NULL;
p->parent = NULL;
p->process = NULL;
p->waitinglist = NULL;
while(q->next)
q = q->next;
q->next =p;
p->next = NULL;
}
void addCOCT() { //添加控制器
NODE *o,*p, *q; //o, 设备; p, 待添加节点;q, 控制器
char ch[20];
o = COCT->next;
q = CHCT->next;
p = (NODE*)malloc(sizeof(NODE));
cout<<"请输入控制器名称:";
cin>>p->name;
cout<<"请输入父节点名称:";
cin>>ch;
while(strcmp(q->name, ch) != 0) {
q = q->next;
if(q == NULL) {
break;
}
}
if(q) {
while(o != NULL) {
if(strcmp(o->parent->name,ch) == 0 && o->next == NULL) {
p->next = NULL;
o->next = p;
p->parent = q;
p->process = NULL;
p->waitinglist = NULL;
break;
}
if(strcmp(o->parent->name,ch) == 0 && strcmp(o->next->parent->name, ch) != 0) {
p->next = o->next;
o->next = p;
p->parent = q;
p->process = NULL;
p->waitinglist = NULL;
break;
}
o = o->next;
}
if(o == NULL) {
o = COCT->next;
while(o->next != NULL) {
o = o->next;
}
o->next = p;
p->next = NULL;
p->parent = q;
p->process = NULL;
p->waitinglist = NULL;
}
}
else
cout<<"没有这个通道"<<endl;
}
void addDCT() { //添加设备
NODE *o,*p, *q; //o,设备; p,添加的节点;q,控制器
char ch[20];
o = DCT->next;
q = COCT->next;
p = (NODE*)malloc(sizeof(NODE));
cout<<"请输入设备名称:";
cin>>p->name;
cout<<"请输入父节点名称:";
cin>>ch;
while(strcmp(q->name, ch) != 0) {
q = q->next;
if(q == NULL) {
break;
}
}
if(q) {
while(o != NULL) {
if(strcmp(o->parent->name,ch) == 0 && o->next == NULL) {

至忻忻忻忻
- 粉丝: 2
最新资源
- python语言视频剪辑软件程序代码QZQ-2025-8-7.txt
- springboot+java校园二手物品交易管理系统毕业论文+答辩稿ppt.rar
- springboot+java校园防诈互动平台的设计与实现毕业论文+答辩稿ppt.rar
- springboot+java校园活动通告交互系统毕业论文+答辩稿ppt.rar
- springboot+java校园交友网站小程序毕业论文+答辩稿ppt.rar
- springboot+java校园旧物交换平台系统的设计与实现毕业论文+答辩稿ppt.rar
- springboot+java校园交友和闲置物品交易平台毕业论文+答辩稿ppt.rar
- springboot+java校园考研论坛系统毕业论文+答辩稿ppt.rar
- springboot+java校园考场座位安排系统设计与实现毕业论文+答辩稿ppt.rar
- springboot+java校园快递物流管理系统毕业论文+答辩稿ppt.zip
- springboot+java校园跑腿系统毕业论文+答辩稿ppt.rar
- springboot+java校园跑腿小程序毕业论文+答辩稿ppt.rar
- springboot+java校园社团信息管理app 毕业论文+答辩稿ppt.rar
- springboot+java校园勤工俭学兼职系统毕业论文+答辩稿ppt.rar
- MySQL如何修改连接数
- 控件设置代码.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


