1、基于多队列反馈的进程调度操作系统综合实训项目设计文档【大纲】(不用打印,提交电子稿即可!)一、 基本信息项目名称:成人姓名、学号、完成日期项目名称:基于时间片的多队列反馈的进程管理系统完成日期:2017.5.24二、 实验内容与目的实验内容:编写程序完成单处理器系统的进程调度,要求采用基于时间片多队列反馈式调度策略调度策略。具体内容:1.确定PCB内容及其组织方式。2.要求模拟进程空闲(新)、就绪、运行、阻塞和完成5个状态。3.实现进程创建、进程调度、进程阻塞、进程唤醒和进程撤销5个原语。4.能够模拟进程从生到灭的完整过程。实验目的: 1.加深进程概念理解,明确进程与程序区别。2.理解操作系统
2、中进程的组织、创建和调度等方法。三、 主要设计思路和流程图设计思路:1定义数据结构2.设置队列3.创建进程4.创建的进程进入就绪队列5.多级反馈调度1.)在第一就绪队列里的进程被调度运行,进程状态由等待变为运行,设置时间片计数器,每次运行加1,时间片满后,该进程出队列,进入下一级别的就绪队列。若是在最后一级别的队列,则在该队列中进行时间片轮转调度2.)运行进程若是被阻塞的话,该进程出就绪队列,进入阻塞队列,状态变为阻塞态3.)若是唤醒被阻塞进程,则阻塞进程根据其时间片计数器计入相应的就绪队列4.)撤销进程,该进程直接出就绪队列四、 主要数据结构及其说明typedef struct Node c
3、har name20; char state;/进程所处的状态,N新建,W等待,B阻塞,R运行,F结束 int round;/时间片计数器 int time;/运行时间 struct Node *next;LinkQueueNode,*PCB;/定义PCBtypedef struct LinkQueueNode *front; LinkQueueNode *rear;LinkQueue;/定义队列void initQueue(LinkQueue *Q)/队列的初始化函数void Initializa()/初始化所有队列void RunPrintf()/打印运行队列void BlockPrint
4、f()/打印阻塞队列void ReadyPrintf(LinkQueue q)/打印就绪队列void putout()/输出函数void EnterQueue(LinkQueue *Q,PCB *p)/进程插入队列函数int DeleteQueue(LinkQueue *Q,PCB *p)/进程出队列void TransferRun(LinkQueue *q1,LinkQueue *q2,PCB q)/进程出就绪队列,入运行队列void Transfer(LinkQueue *q1,LinkQueue *q2,PCB q)/进程唤醒或阻塞时队列转换的函数int MultiDiapatch()/
5、调度函数,若此队列运行的进程时间片满,则进入下一级队列int run()/模拟运行void block()/模拟阻塞void wake()/模拟唤醒int Createprocess(LinkQueue *Q)/进程的创建void meanu()/菜单函数五、 程序运行时的初值和运行结果六、 源程序并附上注释【可是另一个源程序文件,在此应说明该文件名】#include#include#include#includetypedef struct Node char name20; char state;/进程所处的状态,N新建,W等待,B阻塞,R运行,F结束 int round;/时间片计数器
6、int time;/运行时间 struct Node *next;LinkQueueNode,*PCB;/定义PCBtypedef struct LinkQueueNode *front; LinkQueueNode *rear;LinkQueue;int count=0;LinkQueue qRun,qBlock,qReady1,qReady2,qReady3,qReady4;/定义四个就绪队列void initQueue(LinkQueue *Q)/队列的初始化函数 Q-front = (LinkQueueNode *)malloc(sizeof(LinkQueueNode); if(Q-
7、front!=NULL) Q-rear=Q-front; Q-front-next=NULL; void Initializa()/初始化所有队列 initQueue(&qRun); initQueue(&qBlock); initQueue(&qReady1); initQueue(&qReady2); initQueue(&qReady3); initQueue(&qReady4);void RunPrintf()/打印运行队列 PCB p; printf(运行队列:); p=qRun.front-next; while(p) printf(%st,p-name); p=p-next; p
8、=qRun.front-next; printf(n需要时间:); while(p) printf(%dt,p-time); p=p-next; printf(n进程状态:); p=qRun.front-next; while(p) printf(%ct,p-state); p=p-next; void BlockPrintf()/打印阻塞队列 PCB p; printf(nn阻塞队列:); p=qBlock.front-next; while(p) printf(%st,p-name); p=p-next; printf(n需要时间:); p=qBlock.front-next; while
9、(p) printf(%dt,p-time); p=p-next; printf(n进程状态:); p=qBlock.front-next; while(p) printf(%ct,p-state); p=p-next; void ReadyPrintf(LinkQueue q)/打印就绪队列 PCB p; p=q.front-next; while(p) printf(%st,p-name); p=p-next; printf(n需要时间:); p=q.front-next; while(p) printf(%dt,p-time); p=p-next; printf(n进程状态:); p=q
10、.front-next; while(p) printf(%ct,p-state); p=p-next; void putout()/输出函数 PCB p; printf(*n); printf(*多级反馈调度*); printf(n*n); printf(说明:程序中四个就绪队列的时间片分别为10,15,20,30); printf(n*n); printf(*菜单*n); printf(1.创建进程 2.阻塞进程 3.唤醒进程 4.撤销进程 0.退出n); printf(*n); RunPrintf(); BlockPrintf(); printf(nn队 列1:); ReadyPrint
11、f(qReady1); printf(nn队 列2:); ReadyPrintf(qReady2); printf(nn队 列3:); ReadyPrintf(qReady3); printf(nn队 列4:); ReadyPrintf(qReady4); printf(n*n);void EnterQueue(LinkQueue *Q,PCB *p)/进程插入队列函数 (*p)-next=NULL; Q-rear-next=*p; Q-rear=*p;int DeleteQueue(LinkQueue *Q,PCB *p)/进程出队列 if(Q-front=Q-rear) return 0;
12、 *p=Q-front-next; Q-front-next=(*p)-next; if(Q-rear=*p) Q-rear=Q-front; return 1;void TransferRun(LinkQueue *q1,LinkQueue *q2,PCB q)/进程出就绪队列,入运行队列 DeleteQueue(q1,&q); q-state=R; EnterQueue(q2,&q);void runprocess() PCB p; int state1=0,state2=0,state3=0,state4=0; /state来判断就绪队列是否还有进程 if(qReady1.front!=
13、qReady1.rear) TransferRun(&qReady1,&qRun,p); state1=1; else if(qReady2.front!=qReady2.rear) TransferRun(&qReady2,&qRun,p); state2=1; else if(qReady3.front!=qReady3.rear) TransferRun(&qReady3,&qRun,p); state3=1; else if(qReady4.front!=qReady4.rear) TransferRun(&qReady4,&qRun,p); state4=1; if(state1=0
14、&state2=0&state3=0&state4=0) printf(队列中无就绪进程!); else system(cls); putout(); void Transfer(LinkQueue *q1,LinkQueue *q2,PCB q)/进程唤醒或阻塞时队列转换的函数 DeleteQueue(q1,&q); q-state=W; EnterQueue(q2,&q);int MultiDiapatch()/调度函数,若此队列运行的进程时间片满,则进入下一级队列 PCB p; qRun.front-next-time-; +count; if(qRun.front-next-time=
15、0) DeleteQueue(&qRun,&p); free(p); runprocess(); count=0; else if(qRun.front-next-round=count) if(count=10) qRun.front-next-round=15; Transfer(&qRun,&qReady2,p); if(count=15) qRun.front-next-round=20; Transfer(&qRun,&qReady3,p); if(count=20) qRun.front-next-round=30; Transfer(&qRun,&qReady4,p); if(c
16、ount=30) qRun.front-next-round=30; Transfer(&qRun,&qReady4,p); runprocess(); count=0; int run()/模拟运行 if(qRun.front=qRun.rear)/运行队列空,则进行进程队列转换 runprocess(); else MultiDiapatch(); system(cls); putout(); void block()/模拟阻塞 PCB p; if(qRun.front!=qRun.rear)/运行队列不为空,则运行进程出运行队列,进入阻塞队列 DeleteQueue(&qRun,&p);
17、 p-state=B; EnterQueue(&qBlock,&p); system(cls); putout(); else system(cls); putout(); printf(队列中没有进程在运行!); void wake()/模拟唤醒 PCB p; if(qBlock.front!=qBlock.rear) /根据时间片;来决定进入的就绪队列 if(qBlock.front-next-round=10) Transfer(&qBlock,&qReady1,p); else if(qBlock.front-next-round=15) Transfer(&qBlock,&qRead
18、y2,p); else if(qBlock.front-next-round=20) Transfer(&qBlock,&qReady3,p); else if(qBlock.front-next-round=30) Transfer(&qBlock,&qReady4,p); else system(cls); putout(); printf(无等待进程!); void endprocess() PCB p; if(qRun.front=qRun.rear) printf(信息提示:无运行进程,请按Enter键运行进程!); else DeleteQueue(&qRun,&p); free(
19、p); system(cls); putout(); printf(信息提示:选择菜单功能或按Enter键执行进程!); int CompareStr(LinkQueue q,char name20)/比较字符串是否相同 PCB p; p=q.front-next; while(p) if(strcmp(p-name,name)=0) return 0; p=p-next; return 1;int CompareName(char name20) PCB p; p=qRun.front-next; int flag; flag=CompareStr(qRun,name); if(flag=0
20、) return 0; flag=CompareStr(qBlock,name); if(flag=0) return 0; flag=CompareStr(qReady1,name); if(flag=0) return 0; flag=CompareStr(qReady2,name); if(flag=0) return 0; flag=CompareStr(qReady3,name); if(flag=0) return 0; flag=CompareStr(qReady4,name); if(flag=0) return 0; return 1;int Createprocess(Li
21、nkQueue *Q)/进程的创建 PCB p; char n20; p=(PCB)malloc(sizeof(LinkQueueNode); printf(进程名: ); fflush(stdin); scanf(%s,&n); while(!CompareName(n)/判断是否创建了已经创建过的进程 printf(已经有相同名字的进程存在); printf(n请重新输入未创建过的进程:); fflush(stdin); scanf(%s,&n); strcpy(p-name,n); printf(所需时间: ); fflush(stdin); scanf(%d,&(p-time); wh
22、ile(p-timetime); p-state=W; p-round=10; p-next=NULL; EnterQueue(Q,&p);void meanu()/菜单函数 char c; printf(n选择功能:); scanf(%c,&c); while(1) if(c=1) Createprocess(&qReady1); system(cls); putout(); printf(n选择菜单功能或者按enter执行进程:n); while(1) fflush(stdin); scanf(%c,&c); if(c=n) run(); printf(n选择功能或者按enter继续执行:
23、); else break; else if(c=2) block(); printf(n选择功能:); while(1) fflush(stdin); scanf(%c,&c); if(c=n) run(); printf(n选择功能或者按enter继续执行:); else break; else if(c=3) wake(); while(1) fflush(stdin); scanf(%c,&c); if(c=n) run(); printf(n选择功能或者按enter继续执行:); else break; else if(c=4) endprocess(); while(1) fflush(stdin); scanf(%c,&c); if(c=n) run(); printf(n选择功能或者按enter继续执行:); else break; else if(c=0) exit(0); else printf(信息提示: 输入错误!请选择正确的菜单功能选项:); while(1) fflush(stdin); scanf(%c,&c); if(c=n) run(); printf(n选择功能或者按enter继续执行:); else break; int main() Initializa(); putout(); meanu();
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1