操作系统课程设计 设备管理实现 源代码
- 格式:doc
- 大小:58.00 KB
- 文档页数:17
#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);
}
}