《2022年操作系统调度算法 .pdf》由会员分享,可在线阅读,更多相关《2022年操作系统调度算法 .pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、南京信息工程大学实验(实习)报告实验(实习)名称调度算法日期 2011.4.17 得分指导教师毕硕本学院计算机与软件学院专业 软件工程年级 09 班次 2 姓名徐赵飞学号 20091344071 一、实验题目选择五个调度算法,设计实现处理机调度的程序。二、实验目的用简单的程序实现不同算法,即先来先服务算法,最短作业优先算法,轮转调度算法,优先级调度算法和彩票调度算法五种。体现各种算法的实现方式和优缺点,了解不同算法的工作优先级,比较各种算法的不同。三、实验设备及环境:1.硬件设备: PC 机一台。2.软件环境: Windows 操作系统,并安装C+编程语言环境。四、实验内容及要求:用 C+语言
2、实现对多个进程采用多种调度算法执行的模拟(本次实验采用的是:先到先服务算法、优先级调度算法、最短作业优先算法、轮转调度算法和彩票调度算法来实现的。)五、源程序#include #include #include using namespace std; typedef struct run int time; /运行时间int i; /优先级int start; /到达系统时间int wait; /无用数据char data; /数据struct run *next; run,*Run; class System private: Run R; Run N; Run Y; Run L; Run
3、 S; public: void FCFS(); void SJF(); void RR(); void YXJ(); /优先级调度void TICKET(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 10 页 - - - - - - - - - ; /*FSFC*/ void System:FCFS() Run p,r; char x1; int flag,x2,x3,x4,x5=0,x6=1,x7=0,x8,x9; float sum100; sum0=0;
4、R=new run; R-next=NULL; r=R; coutplease put in flagflag; coutplease put in !data! time! i! start !wait !flag!x1; cinx2; cinx3; cinx4; cinx9; cinflag; p=new run; p-data=x1; p-time=x2; p-i=x3; p-start=x4; p-wait=x9; r-next=p; r=p; x5+; if(R-next)p=R-next; else p=R; while(x5) sumx6=sumx6-1+(p-time); co
5、utdatanext; x5-; x6+; x6-; x8=x6; x7=0; while(x6) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 10 页 - - - - - - - - - x7=x7+sumx6; x6-; x7=x7/x8; coutx7endl; coutFCFS!next=NULL; p2=new run; p4=new run; r=N; coutplease put in !flag!flag; coutplease put in !dat
6、a! time! i! start !wait !flag!x1; cinx2; cinx3; cinx4; cinx5; cinflag; p1=new run; p1-data=x1; p1-time=x2; p1-i=x3; p1-start=x4; p1-wait=x5; p2=N; x7=0; while(x7next-timetime) p2=p2-next; x7+; if(x7=x6) r-next=p1; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共
7、10 页 - - - - - - - - - r=p1; else p1-next=p2-next; p2-next=p1; x6+; p2=N-next; x8=x6; while(x8) sumx9=sumx9-1+(p2-time); coutdatanext; x8-; x9+; x9-; x8=x6; x7=0; while(x9) x7=x7+sumx9; x9-; x9=1; x7=x7/x6; cout平均作业周转时间endl; coutx7next; while(x8) sumx9=sumx9/p2-time; p2=p2-next; z=z+sumx9; x9+; x8-;
8、 z=z/x6; cout平均带权作业周转时间endl; coutzendl; coutSJFnext=NULL; r=L; coutplease put in !time0!time0; coutplease put in !flag!flag; coutplease put in !data! time! i! start !wait !flag!x1; cinx2; cinx3; cinx4; cinx5; cinflag; p1=new run; p1-data=x1; p1-time=x2; p1-i=x3; p1-start=x4; p1-wait=x5; r-next=p1; r
9、=p1; x6+; m=x6; n=m; while(m) / 按时间片轮转输出p5=L; for(n=m;n0;n-) if(p5-next-time0) p5-next-time=p5-next-time-time0; coutnext-datanext; else p5-next=p5-next-next; m-; coutendl; coutRR!next=NULL; p2=new run; p4=new run; r=Y; coutplease put in !flag!flag; coutplease put in !data! time! i! start !wait !flag
10、!x1; cinx2; cinx3; cinx4; cinx5; cinflag; p1=new run; p1-data=x1; p1-time=x2; p1-i=x3; p1-start=x4; p1-wait=x5; p2=Y; x7=0; while(x7next-ii) p2=p2-next; x7+; if(x7=x6) r-next=p1; r=p1; else p1-next=p2-next; p2-next=p1; x6+; p2=Y-next; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 -
11、 - - - - - - 第 6 页,共 10 页 - - - - - - - - - x8=x6; while(x8) coutdatanext; x8-; coutYXJ!next=NULL; r=S; coutplease put in !flag!flag; coutplease put in !time0!time0; coutplease put in !data! time! i! start !wait !flag!x1; cinx2; cinx3; cinx4; cinx5; cinflag; p1=new run; p1-data=x1; p1-time=x2; p1-i=
12、x3; p1-start=x4; p1-wait=x5; r-next=p1; r=p1; x6+; x7=x6; while(x7) z=rand(); while(z=0)z=rand(); if(z0;m-) p2=p2-next; if(p2-time=time0) coutdatatime=p2-time-time0; else p3=S; while(p3-next!=p2)p3=p3-next; p3-next=p2-next; x7-; coutTICKET!endl; int main() System S; S.FCFS(); S.SJF(); S.RR(); S.YXJ(
13、); S.TICKET(); return 0; (1)先来先服务算法(2)最短作业优先算法名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 10 页 - - - - - - - - - (3)轮转调度算法(4)优先级调度算法(5)彩票调度算法名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 10 页 - - - - - - - - - 六、实验总结通过本次实验我对操作系统的8 种算法有了更加深刻的了解。通过这次实验我也体会到了思路的重要性,在编程之前将结构设计完善,才能顺利进行。名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 10 页 - - - - - - - - -
限制150内