操作系统原理课程设计_第1页
操作系统原理课程设计_第2页
操作系统原理课程设计_第3页
操作系统原理课程设计_第4页
操作系统原理课程设计_第5页
免费预览已结束,剩余7页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、操作系统原理课程设计课题名称:进程调度算法姓 名:班 级:学 号:课程设计起止时间:2005年1月2日 2005年1月7日指导教师:成绩:课程设计任务书操作系统原理课程设计任务书(同学填写)设计题目:进程调度算法任务下达时间:2005年1月2日任务完成时间:2005年1月7日指导教师:指导教师评语(教师填写)一、所得结果:一、存在问题:成绩评阅人进程调度算法一、设计说明该程序实现了进程的创建,且对该进程队列进行动态优先权抢占式和时间片轮转算 法的调度。二、详细设计1. 流程图选择anum选择1选择23选择执行动态优先权算法退出创建进程2. 程序运行环境束Turbo C 2.03. 变量的名称、

2、作用及含义说明链表结构process,整型变量name表示进程名称,整型变量prior表示优先数,整型变量needtime表示需要执行时间,整型变量CPUtime表示CPU执行时间,整型变量run time表示进程执行时间, 整型变量state表示运行状态(1:ready, 2:execute, 3:fi nish )。4. 各主要模块的功能表述子函数 Createp()用来创建新进程,其中的整型变量n表示需要创建的进程个数; Prin tP1(h)用来打印输出时间片轮转算法的创建进程和运行进程的各变量值; Finish(h)用来判断某个进程是否执行完; Find(h)用来查找该进程队列中优先

3、数最大的进程; PrintP2(h)用来打印输出动态优先权抢占式算法的创建进程和运行进程的各变量值; ExecuteP_prio(h)执行动态优先权抢占式进程调度算法; ExecuteP_time(h)执行时间片轮转进程调度算法;主函数main ()中使用字符变量select表示a和b中的一个字母,整型变量num表示1至3中的一个数,用双层 switch语句实现各模块功能。5. 程序源代码#in clude<stdio.h>#include<conio.h>#include<stdlib.h>#include<dos.h>#define NULL

4、 0#define Max_Pri 100struct Processint name;int prio;int needtime;int piecetime;int CPUtime;int runtime;int state;struct Process *next;typedef struct Process process;/*/process *CreateP()process *h,*t,*p;int i,a;int ct=0;for(i=0;i<5;i+)t=(process *)malloc(sizeof(process); printf("n Enter the

5、 name of process:"); scanf("%d",&a);printf("nEnter the CPUtime of process:"); scanf("%d",&ct);t->name=a;t->CPUtime=ct;t->runtime=0;t->prio=100-t->CPUtime; t->needtime=t->CPUtime;t->piecetime=t->CPUtime/2+t->CPUtime%2; t->sta

6、te=1;if(i=0)h=t;p=t;elsep->next=t; p=p->next; p->next=NULL; return h;/*/void PrintP1(process*h)process*t;t=h;printf(" 1:ready 2:execute 3:finish ");printf("n name priority needtime runtime staten");while(t) printf("n%4d%8d%10d%10d%10d",t->name,t->prio,t-&

7、gt;needtime,t->runtime, t->state);t=t->next; putchar('n');/*/void PrintP2(process *h)process *t;t=h;printf(" 1:ready 2:execute 3:finish ");printf("n name piecetime needtime runtime CPUtime staten"); while(t)printf("n%4d%8d%10d%10d%10d%8d",t->name,t-&

8、gt;piecetime,t->needtime,t->runtime, t->CPUtime,t->state);t=t->next;putchar('n');/*/int Finish(process *h)int i=1;process *p;p=h;if (h!=NULL)doif (p->state!=3)i=0;break;else p=p->next; while (p!=NULL);return i;/*/process*Find(process *h)int max;process *p,*t;p=t=h;if (h!

9、=NULL)max=p->prio;while(p)p=p->next;if (max<p->prio) max=p->prio; while(t)if (max=t->prio)return t;else t=t->next;/*/ process *ExecuteP_prio(process *h)process *t;while (Finish(h)=0)if (h!=NULL) clrscr(); t=Find(h);if (t->needtime<=1) t->needtime=0; t->state=3; else

10、t->needtime-=1; t->state=2;if (t->runtime<t->CPUtime) t->runtime+=1; t->prio-=3;PrintP1(h);if (t->state!=3)sleep(1);t->state=1;sleep(3);/*/process *ExecuteP_time(process *h)process *t;while (Finish(h)=0)t=h;if (h!=NULL)while(t)clrscr();if (t->needtime<=2)t->state=

11、3;t->needtime=0;elset->needtime-=2;t->state=2;if (t->piecetime>0) t->piecetime-=1;if (t->runtime<t->CPUtime) t->runtime+=2;PrintP2(h);if (t->state!=3) sleep(1);if (t->state!=3) t->state=1;t=t->next;sleep(3);/*/main()int num,count; char select; process *p=NUL

12、L;while (1) clrscr(); printf("ntprintf("t a.Priority. printf("t b.Piece of time. printf("tprintf("Enter a letter a or b:"); scanf("%s",&select); switch (select) case 'a':clrscr();while(1)printf("ntprintf("tprintf("tprintf("tn&qu

13、ot;);n");n");1.Create a new process. n");2.Execute process.n");3.Exit.n");printf("tn");printf("Enter a number between 1 to 3:"); scanf("%d",&num);switch (num)case 1:printf("This step is create a process.n"); p=CreateP();n");n&

14、quot;);PrintP1(p);break;case 2:printf("This step is execute a process by priority.n"); ExecuteP_prio(p);PrintP1(p);break;case 3:exit(0);break;default : printf("nPlease input right select!n"); break; case 'b':clrscr();while(1)printf("ntn");printf("t 1.Create

15、 a new process. n");printf("t 2.Execute process.n");printf("t 3.Exit.n");printf("tn");printf("Enter a number between 1 to 3:"); scanf("%d",&num);switch (num)case 1:printf("This step is create a process.n");p=CreateP();PrintP2(p);br

16、eak;case 2:prin tf("This step is execute a process by piece of time.' n"); ExecuteP_time(p);Prin tP2(p);break;case 3:exit(0);break;default : prin tf("n'tPlease in put right select!n"); break;default : prin tf("n'tPlease in put right select!n"); break;三、运行结果四、分析结果进程控制块采用链表结构体,进程控制块中进程标示符、进程优先数、需要执行时间、 时间片数、CPU执行时间、进程运行时间、进程状态均采用整型。将程序源代码清单装入 C环境,Ctrl+F9运行程序,检查错误,如果检查无误,进行如下 操作:第一步:输入“ a.”执行动态优先权抢占式进程调度算法,根据提示输入“1 ”创建进

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论