




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 char name20;
3、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 BlockPrintf()/打印阻塞队列voi
4、d 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<stdio.h>#include<stdlib.h>#include<dos.h>#include<String.h>typedef struct Node char name20; char state;
6、/进程所处的状态,N新建,W等待,B阻塞,R运行,F结束int round;/时间片计数器 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 = (L
7、inkQueueNode *)malloc(sizeof(LinkQueueNode); if(Q->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(
8、)/打印运行队列PCB p;printf("运行队列:"); p=qRun.front->next; while(p) printf("%st",p->name); p=p->next; p=qRun.front->next; printf("n需要时间:"); while(p) printf("%dt",p->time); p=p->next; printf("n进程状态:"); p=qRun.front->next;while(p) printf(&
9、quot;%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(p) printf("%dt",p->time); p=p->next; p
10、rintf("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(&qu
11、ot;%dt",p->time); p=p->next; printf("n进程状态:"); p=q.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"
12、);printf("n*n");printf("*菜单*n"); printf("1.创建进程 2.阻塞进程 3.唤醒进程 4.撤销进程 0.退出n"); printf("*n"); RunPrintf();BlockPrintf();printf("nn队 列1:");ReadyPrintf(qReady1);printf("nn队 列2:");ReadyPrintf(qReady2);printf("nn队 列3:");ReadyPrintf(qRea
13、dy3);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; *p=Q->front->next; Q->front-&
14、gt;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(qRea
15、dy1.front!=qReady1.rear) TransferRun(&qReady1,&qRun,p);state1=1; elseif(qReady2.front!=qReady2.rear) TransferRun(&qReady2,&qRun,p);state2=1;elseif(qReady3.front!=qReady3.rear) TransferRun(&qReady3,&qRun,p);state3=1;elseif(qReady4.front!=qReady4.rear) TransferRun(&qReady4,
16、&qRun,p);state4=1;if(state1=0&&state2=0&&state3=0&&state4=0)printf("队列中无就绪进程!");elsesystem("cls");putout();void Transfer(LinkQueue *q1,LinkQueue *q2,PCB q)/进程唤醒或阻塞时队列转换的函数 DeleteQueue(q1,&q); q->state='W' EnterQueue(q2,&q);int MultiD
17、iapatch()/调度函数,若此队列运行的进程时间片满,则进入下一级队列 PCB p;qRun.front->next->time-;+count;if(qRun.front->next->time=0)DeleteQueue(&qRun,&p);free(p);runprocess();count=0;elseif(qRun.front->next->round=count)if(count=10)qRun.front->next->round=15;Transfer(&qRun,&qReady2,p); if
18、(count=15)qRun.front->next->round=20;Transfer(&qRun,&qReady3,p); if(count=20)qRun.front->next->round=30;Transfer(&qRun,&qReady4,p); if(count=30)qRun.front->next->round=30;Transfer(&qRun,&qReady4,p);runprocess(); count=0;int run()/模拟运行 if(qRun.front=qRun.rear
19、)/运行队列空,则进行进程队列转换 runprocess();elseMultiDiapatch();system("cls");putout();void block()/模拟阻塞 PCB p;if(qRun.front!=qRun.rear)/运行队列不为空,则运行进程出运行队列,进入阻塞队列 DeleteQueue(&qRun,&p);p->state='B'EnterQueue(&qBlock,&p);system("cls");putout();elsesystem("cls&qu
20、ot;);putout();printf("队列中没有进程在运行!");void wake()/模拟唤醒 PCB p;if(qBlock.front!=qBlock.rear)/根据时间片;来决定进入的就绪队列 if(qBlock.front->next->round=10) Transfer(&qBlock,&qReady1,p);elseif(qBlock.front->next->round=15) Transfer(&qBlock,&qReady2,p);elseif(qBlock.front->next
21、->round=20) Transfer(&qBlock,&qReady3,p);elseif(qBlock.front->next->round=30) Transfer(&qBlock,&qReady4,p);elsesystem("cls");putout();printf("无等待进程!");void endprocess() PCB p;if(qRun.front=qRun.rear)printf("信息提示:无运行进程,请按Enter键运行进程!");elseDeleteQ
22、ueue(&qRun,&p);free(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
23、->next;int flag;flag=CompareStr(qRun,name);if(flag=0) 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,na
24、me); if(flag=0) return 0; return 1;int Createprocess(LinkQueue *Q)/进程的创建 PCB p;char n20;p=(PCB)malloc(sizeof(LinkQueueNode);printf("进程名: ");fflush(stdin);scanf("%s",&n);while(!CompareName(n)/判断是否创建了已经创建过的进程 printf("已经有相同名字的进程存在");printf("n请重新输入未创建过的进程:");f
25、flush(stdin);scanf("%s",&n);strcpy(p->name,n);printf("所需时间: ");fflush(stdin);scanf("%d",&(p->time);while(p->time<0)printf("输入不合法");fflush(stdin);scanf("%d",&(p->time);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&
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论