




免费预览已结束,剩余8页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
99计算机(2)班 戴虎 99031045 操作系统课程设计 -进程调度算法模拟一、 实验内容:模拟五种进程调度算法并计算各参数值二、 实验原理:(1) 先来先服务调度:最先到达的进程先进行调度(2) 短作业优先调度:从已到达的进程中选出最短的进程优先调度(3) 时间片轮转调度:每个进程依次的按时间片轮流的方式执行(4) 静态优先权调度:赋予优先权,在已到达的进程中选出优先权最高的优先调度(5) 高响应比优先调度:优先权随等待时间而增加,从而使等待时间较长且服务时间较短的进程优先调度响应比=1+等待时间/服务时间三、 实验设计说明:本程序采用C+ Builder 5编程和设计界面考虑到调度算法较多,采用了多页面的界面(如下图),加入的进程限制五个,在文本框中模拟到达一进程后,输入到达时间和服务时间,点击“加入新进程”即可,输入完成之后,点击运行即可得到表中各值。想从新输入可点击“清除”按钮。关闭时直接点击“”即可。该程序还不是很完善,有一些小问题,尚待解决,还得向老师请教。 四、 实验结果:(只打印两个结果示范)运行后操作面板初始化如下图: 短作业优先结果如图:时间片轮转结果如图:(书上的例题)五、 实验源程序:Unit1.h文件/-#ifndef Unit1H#define Unit1H/-#include #include #include #include #include #include #include /-class TForm1 : public TForm_published:/ IDE-managed Components 共13页 第13页TPageControl *PageControl1;TTabSheet *TabSheet1;TTabSheet *TabSheet2;TTabSheet *TabSheet3;TTabSheet *TabSheet4;TabSheet *TabSheet5; TStringGrid *sgr;TButton *Button1;TButton *Button2;TButton *Button3;TStringGrid *sgr1;TButton *Button4;TButton *Button5;TButton *Button6;TStringGrid *sgr2;TButton *Button7;TButton *Button8;TButton *Button9;TStringGrid *sgr3;TButton *Button10;TButton *Button11;TButton *Button12;TStringGrid *sgr4;TButton *Button13;TButton *Button14;TButton *Button15;TLabel *Label1;TEdit *Edit1;TLabel *Label2;TEdit *Edit2;TEdit *Edit3;TEdit *Edit4;TLabel *Label3;TLabel *Label4;TEdit *Edit5;TLabel *Label5;TLabel *Label6;TEdit *Edit6;TLabel *Label7;TEdit *Edit7;TLabel *Label8;TLabel *Label9;TLabel *Label10;TEdit *Edit8;TEdit *Edit9;TEdit *Edit10;TLabel *Label11;TLabel *Label12;TEdit *Edit11;TEdit *Edit12;void _fastcall FormCreate(TObject *Sender);void _fastcall Button3Click(TObject *Sender);void _fastcall Button1Click(TObject *Sender);void _fastcall Button2Click(TObject *Sender);void _fastcall Button6Click(TObject *Sender);void _fastcall Button5Click(TObject *Sender);void _fastcall Button4Click(TObject *Sender);void _fastcall Button9Click(TObject *Sender);void _fastcall Button7Click(TObject *Sender);void _fastcall Button8Click(TObject *Sender);void _fastcall Button12Click(TObject *Sender);void _fastcall Button10Click(TObject *Sender);void _fastcall Button11Click(TObject *Sender);void _fastcall Button15Click(TObject *Sender);void _fastcall Button13Click(TObject *Sender);void _fastcall Button14Click(TObject *Sender);private:/ User declarationspublic:/ User declarations _fastcall TForm1(TComponent* Owner);/-extern PACKAGE TForm1 *Form1;/-#endif *Unit1.cpp文件/-#include #pragma hdrstop#include Unit1.h/-#pragma package(smart_init)#pragma resource *.dfmTForm1 *Form1;float super6; /优先权float come6; /到达时间float serve6; /服务时间float begin6; /开始执行时间float end6; /完成时间float all6; /周转时间float dall6; /带权周转时间float max(float,float,float);/-_fastcall TForm1:TForm1(TComponent* Owner) /初始化表格 : TForm(Owner)/-void _fastcall TForm1:FormCreate(TObject *Sender)sgr-Cells00=进程名;sgr1-Cells00=进程名;sgr2-Cells00=进程名;sgr3-Cells00=进程名;sgr4-Cells00=进程名;sgr3-Cells01=优先权;sgr-Cells01=到达时间;sgr1-Cells01=到达时间;sgr2-Cells01=到达时间;sgr3-Cells02=到达时间;sgr4-Cells01=到达时间;sgr-Cells02=服务时间;sgr1-Cells02=服务时间;sgr2-Cells02=服务时间;sgr3-Cells03=服务时间;sgr4-Cells02=服务时间;sgr-Cells03=开始执行时间;sgr1-Cells03=开始执行时间;sgr3-Cells04=开始执行时间;sgr4-Cells03=开始执行时间;sgr4-Cells04=等待时间;sgr4-Cells05=响应比;sgr-Cells04=完成时间;sgr1-Cells04=完成时间;sgr2-Cells03=完成时间;sgr3-Cells05=完成时间;sgr4-Cells06=完成时间;sgr-Cells05=周转时间;sgr1-Cells05=周转时间;sgr2-Cells04=周转时间;sgr3-Cells06=周转时间;sgr4-Cells07=周转时间;sgr-Cells06=带权周转时间;sgr1-Cells06=带权周转时间;sgr2-Cells05=带权周转时间;sgr3-Cells07=带权周转时间;sgr4-Cells08=带权周转时间;sgr-Cells07=显示调度结果;sgr1-Cells07=显示调度结果;sgr3-Cells08=显示调度结果;sgr4-Cells09=显示调度结果;/-/先来先服务调度算法void _fastcall TForm1:Button3Click(TObject *Sender) /输入初值,5个static int i=1;sgr-Cellsi0=i; /进程编号sgr-Cellsi1=Edit1-Text; /输入到达时间comei=StrToFloat(Edit1-Text); /赋到达时间给表格sgr-Cellsi2=Edit2-Text; /输入服务时间servei=StrToFloat(Edit2-Text); / 赋服务时间给表格i+;if(i5) i=1;/-float max(float x,float y,float m) /定义函数 return (x+y)m?(x+y):m; /-/“运行”按键函数void _fastcall TForm1:Button1Click(TObject *Sender) int i=1;begin1=come1;sgr-Cells13=begin1; /初始值for(i=2;iCellsi3=begini; /开始执行时间for(i=1;iCellsi4=endi; alli=endi-comei; sgr-Cellsi5=alli; dalli=alli/servei; sgr-Cellsi6=dalli; sgr-Cellsi7=i; /-/“清除”按键函数void _fastcall TForm1:Button2Click(TObject *Sender) int i=0,j=0;for(i=0;i=7;i+) for(j=1;jCellsji=; /-/短作业优先调度函数/“加入新进程”输入初值void _fastcall TForm1:Button6Click(TObject *Sender) static int i=1;sgr1-Cellsi0=i; /进程编号sgr1-Cellsi1=Edit3-Text; comei=StrToFloat(Edit3-Text);sgr1-Cellsi2=Edit4-Text;servei=StrToFloat(Edit4-Text);i+;if(i5) i=1;/-/“清除”按键函数void _fastcall TForm1:Button5Click(TObject *Sender) int i=0,j=0; for(i=0;i=7;i+) for(j=1;jCellsji=; /-/“运行”按钮函数void _fastcall TForm1:Button4Click(TObject *Sender) int i,j,k,run=1,index=1,flag6=1,1,1,1,1,1,t4; /flag用于设置访问值“1”为未访问 sgr1-Cells17=1; begin1=come1; sgr1-Cells13=FloatToStr(begin1); end1=begin1+serve1; sgr1-Cells14=FloatToStr(end1); sgr1-Cells15=FloatToStr(end1-come1); sgr1-Cells16=FloatToStr(end1-come1)/serve1); /初始化 for(j=1;j5) /index值的复位 for(k=2;k=5;k+) if (flagk=1) index=k; /index指向第一个未执行的进程 break; for(i=2;i=5;i+) /满足三个条件的进程才可调度,1、已到达2、未调度过3、服务时间最小 if (comeiservei)&(flagi=1) index=i; else if (comeiendrun) /如果一进程完成未有进程到达,则下一个进程到来就直接调度 break; flagindex=0; /处理index,index为当前运行的进程编号,run为上一个进程的编号 beginindex=max(serverun,beginrun,comeindex); /开始执行时间 sgr1-Cellsindex3=FloatToStr(beginindex); run=index; endindex=beginindex+serveindex; /计算完成时间 sgr1-Cellsindex4=FloatToStr(endindex); allindex=endindex-comeindex; /计算周转时间 sgr1-Cellsindex5=FloatToStr(allindex); sgr1-Cellsindex6=FloatToStr(allindex/serveindex); /赋带权周转时间 tj=index; / tj为调度序列 for(i=1;iCellsi+17=FloatToStr(ti); /显示调度结果 /-/时间片轮转调度算法void _fastcall TForm1:Button9Click(TObject *Sender)static int i=1;sgr2-Cellsi0=i; /进程编号sgr2-Cellsi1=Edit5-Text;comei=StrToFloat(Edit5-Text);sgr2-Cellsi2=Edit6-Text;servei=StrToFloat(Edit6-Text);i+;if(i5) i=1;/-/“运行”按钮函数void _fastcall TForm1:Button7Click(TObject *Sender) int i=1,j=1,flag6=1,1,1,1,1,1; float t=0,q,a6; / q为时间片大小 q=StrToFloat(Edit7-Text); /赋值给q for(i=1;i=5;i+) ai=servei; for(j=1;j=100;j+) /设总时间片不超过100 for(i=1;i0) t+=q; /t为当前执行的总时间 else if(servei=0) t+=(q+servei); /t为当前执行的总时间 endi=t; /进程调度完毕送完成时间 flagi=0; /一旦进程被调度后置flag值为0 for(i=1;iCellsi3=FloatToStr(endi); alli=endi-comei; sgr2-Cellsi4=FloatToStr(alli); sgr2-Cellsi5=FloatToStr(alli/ai); /-/“清除”按键函数void _fastcall TForm1:Button8Click(TObject *Sender)int i=0,j=0; for(i=0;i=6;i+) for(j=1;jCellsji=; /-/优先权调度算法 ( 原理类似短作业优先)/“加入新进程”输入初值void _fastcall TForm1:Button12Click(TObject *Sender)static int i=1;sgr3-Cellsi0=i; /进程编号sgr3-Cellsi1=Edit8-Text;superi=StrToFloat(Edit8-Text);sgr3-Cellsi2=Edit9-Text;comei=StrToFloat(Edit9-Text);sgr3-Cellsi3=Edit10-Text;servei=StrToFloat(Edit10-Text);i+;if(i5) i=1;/-/“运行”按钮函数void _fastcall TForm1:Button10Click(TObject *Sender) int i,j,k,run=1,index=1,flag6=1,1,1,1,1,1,t4; /run为上一个调度的进程号 sgr3-Cells18=1; begin1=come1; sgr3-Cells14=FloatToStr(begin1); end1=begin1+serve1; sgr3-Cells15=FloatToStr(end1); sgr3-Cells16=FloatToStr(end1-come1); sgr3-Cells17=FloatToStr(end1-come1)/serve1); /初始化for(j=1;j5) /index值的复位 for(k=2;k=5;k+) if (flagk=1) index=k; break; for(i=2;i=5;i+) if (comeisuperi)&(flagi=1) index=i; /满足条件的进程号送给index else if (comeiendrun) break; flagindex=0; /处理index beginindex=max(serverun,beginrun,comeindex); sgr3-Cellsindex4=FloatToStr(beginindex); run=index; endindex=beginindex+serveindex; sgr3-Cellsindex5=FloatToStr(endindex); allindex=endindex-comeindex; sgr3-Cellsindex6=FloatToStr(allindex); sgr3-Cellsindex7=FloatToStr(allindex/serveindex); tj=index; for(i=1;iCellsi+18=FloatToStr(ti);/-/“清除”按键函数void _fastcall TForm1:Button11Click(TObject *Sender)int i=0,j=0; for(i=0;i=9;i+) for(j=1;jCellsji=;/-/高响应比优先调度算法 (类似优先权调度算法,响应比为动态的)/“清除”按键函数void _fastcall TForm1:Button15Click(TObject *Sender)static int i=1;sgr4-Cellsi0=i; /进程编号sgr4-Cellsi1=Edit11-Text;comei=StrToFloat(Edit11-Text);sgr4-Cellsi2=Edit12-Text;servei=StrToFloat(Edit12-Text);i+;if(i5) i=1;/-/“运行”按钮函数void _fastcall TForm1:Button13Click(TObject *Sender)int i,j,k,run=1,index=1,flag6=1,1,1,1,1,1,t4;float xy6; /xy为响应比数组 sgr4-Cells19=1; begin1=come1; sgr4-Cells13=FloatToStr(begin1); sgr4-Cells14=0; xy1=1+0; sgr4-Cells15=FloatToStr(xy1); end1=begin1+serve1; sgr4-Cells16=FloatToStr(end1); sgr4-Cells17=FloatToStr(end1-come1); sgr4-Cells18=FloatToStr(end1-come1)/serve1); /初始化 for(j=1;j5) for(k=2;k=5;k+) if (flagk=1) index=k; break; for(i=2;i=5;i+) if (comeiendrun)& (endrun-comeindex)/serveindexendrun) break; flagindex=0; /处理index beginindex=max(serverun,beginrun,comeindex); sgr4-Cellsindex3=FloatToStr(beginindex); sgr4-Cellsin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 砂料机安装外包协议合同
- 生产经营纠纷调解协议书
- 项目部租赁泵车合同范本
- 研发产品转化协议书模板
- 烤肉桌椅转让协议书模板
- 机关食堂承包合同协议书
- 物业服务业务协议书范本
- 焊工培训考试协议书模板
- 空压机租赁转让合同范本
- 阳台栏杆改造安全协议书
- 中远海运招聘笔试题库2025
- 2025年陕西省中考英语试题卷(含答案及解析)
- 劳动合同(模版)4篇
- 牛腿计算表(自动版)
- 甲苯甲醇烷基化法年产30万吨对二甲苯车间设计分析
- 碳纤维项目招商方案【模板参考】
- 电磁屏蔽网施工工法(十公司)
- 100-200吨垃圾焚烧炉工艺方案、投资预算、运行成本分析
- 会计分岗实训教案
- 经典:危重病人的早期识别与评估
- 质量控制实验室与物料系统—12.实验室设备和分析仪器的管理
评论
0/150
提交评论