操作系统 处理机调度 课程设计报告.docx
《操作系统 处理机调度 课程设计报告.docx》由会员分享,可在线阅读,更多相关《操作系统 处理机调度 课程设计报告.docx(22页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、中南大学操作系统课程设计报告设计报告题目:处理机调度模拟程序 学院:信息科学与工程学院专业:电子信息0802姓名:王昊学号:学09080925 指导教师:张晓 完成时间:2011年7月12日Prtl()结束四.操作截图:主界面设计:(1,2,3算法4退出)K:S作系统课程设HSb理机选良.exeCOMPUTER OS BORKBy wanghao(Class 2 c Hoose one oF f o Ho v/in sr :1-PRIORITY.2.ROUNDROBIN.3-SHORTTASK-4 . EX I T - please enter* yom cHo ice ;七工算法L动态优先级
2、算法算法2:时间片轮转法算法3:短作业优先法s五.程序源代码#include #include #include #include typedef struct node(char name10;int prio;int round;int cputime;int needtime;int count;char state;struct node *next;PCB;PCB *Enish,*ready,*tail,*run;int N;firstin()(run=ready;run-state=R,; ready=ready-next;)int timesj(void)(int i,xt;ti
3、me 11;srand(unsigned) time(&t);xt 二 rand() % 10 +1;return xt;void prt l(char a)(if(toupper(a)=,r)printf(n name cputime needtime priority statenn);elseif(toupper(a)=21)printf(n name cputime needtime priority statenn);elseprintf(H name cputime needtime priority statenH); )void prt2(char a,PCB *q)(if(t
4、oupper(a)=,r)printf(n %-l Os%-1 Od%-1 Od%-1 Od %cnn,q-name,q-cputime,q-needtime,q-prio,q-state);elseif(toupper(a)=,2,)printf(n %-l Os%-1 Od%-1 Od%-1 Od %cnq-name,q-cputime,q-needtime,q-prio,q-state);elseprintf(n %-lOs%-1 Od%-1 Od%-1 Od %cnH,q-name,q-cputime,q-needtime,q-prio,q-state);)void prt(char
5、algo)(PCB *p;prtl(algo);if(run!=NULL)prt2(algo,run);p = ready;while(p!=NULL)(prt2(algo,p);p=p-next;)p=finish;while(p!=NULL)prt2(algo,p); p=p-next;getch();return;)insert 1(PCB *q)(PCBint b;s=q;pl=ready;r=pl;b=l;while(pl!=NULL)&b) if(p 1 -prio=s-prio) (r=pl;pl=pl-next;)elseb=0;if(r!=pl)r-next=s; s-nex
6、t=pl;)else(s-next=pl; ready=s;)insert2(PCB *p2)(tail-ncxt=p2;tail=p2;p2-next=NULL;) insert3(PCB *q)PCB *pl,*s,*r;int b;s=q;pl=ready;r=pl;b二l;while(pl!=NULL)&b)if(p 1 -needtimeneedtime)(r=pl;pl=pl-next;)elseb=0;if(r!=pl)(r-next=s;s-next=pl;else(s-next=pl;ready=s;)void create 1 (char alg)(PCB *p;int i
7、,time,sjt,priost;char na10;ready=NULL;finish=NULL;run=NULL;printf(nEnter name and time of process。);printf(Hnn);for(i=l;iname,na);p-cputime=O;p-needtime=sjt;p-state=,w,;p-prio=20-sjt;if(ready!=NULL)insert l(p);elsep-next=ready;ready=p;printf(HDisplay Process Of Priority :nH);printf(H-nn);prt(alg);ru
8、n=ready;ready=ready-next;run-state=R,;)void create2(char alg)PCB *p;int i,time,sjt;char na10;ready=NULL;finish=NULL;run=NULL;printf(HEnter name and time of round processnH);printf(n-nn);for(i=l;iname,na);p-cputime=O;p-needtime=sjt;p-round=l;p-state=,w,;p-count=0;p-prio=20-sjt;if(ready!=NULL)insert2(
9、p);else(p-next=ready;ready二p;tail=p;)printf(nDisplay Process Of Roundrobinnn);printf(n-nn);prt(alg);run=ready;ready=ready-next;run-state=R,;)void create3(char alg)(PCB *p;int i,time,sjt;char na10;ready二NULL;finish=NULL;run=NULL;printf(nEnter name and time of processnH);printf(nnn);for(i=l;iname,na);
10、p-cputime=O;p-needtime=sjt;p-state=,w,;p-prio=20-sjt;if(ready!=NULL)insert l(p);elsep-next=ready;ready=p;)printf(HDisplay Process Of Priority :nH);printf(H-nn);prt(alg);run=ready;ready=ready-next;run-state=R;)priority(char alg)(while(run! =NULL)(run-cputime=run-cputime+1; run-nccdtimc=run-nccdtimc-l
11、;run-prio=run-prio-l;if(run-needtime=O) (run-next=finish;finish=run;run-state=,C,;run二NULL;if(ready!=NULL) firstinQ;)elseif(ready! =NULL)&(run-prioprio) (run-state=,W,;insert! (run); firstin();) prt(alg);)roundrun(char alg)(while(run!=NULL)(run-cputime=run-cputime+1;run-needtime=run-needtime-1;run-c
12、ount=run-count+l; run-prio=run-prio-l;if(run-needtime=O) run-next=finish;finish=run;run-state=,C,;run=NULL;if(ready!=NULL) firstin();elseif(run-count=run-round)run-count=0;if(ready!=NULL)(run-state=,W,;insert2(run);firstin();目录一、课程设计题目3二、基本概念及思想3三、部分程序主要流程图9四、操作截图11五、程序源代码12六、心得体会及总结21prt(alg);)shor
13、ttask(char alg)(while(run! =NULL)(run-cputime=run-cputime+l;run-needtime=run-needtime-1;run-prio=run-prio-1;if(run-needtime=O) (run-next=finish;finish=run;run-state=C,;run=NULL;if(ready!=NULL)firstin();)elseif(ready !=NULL)&(run-needtimeready-needtime)(run-state=,W,;insert 1 (run);firstin();) prt(al
14、g);) return;)menu() char algo;printf(nnnCOMPUTER OS WORKnnf);printf(HnnBy wanghao(Class 2) nnnn);printf(n choose one of following:nn);printf(nnl.PRIORITY.nnn);printf(n2.ROUNDROBIN.nnH);printf(n3.SHORTTASK.nnn);printf(n4.EXIT.nnnn);printf(Hn please enter your choice:); scanf(n%cn,&algo);if(algo= 1)(p
15、rintf(nEnter process numbernn);scanf(d”,&N);create 1 (algo);priority(algo);)elseif(algo=t2,)(printf(HEnter process numbernn);scanf(n%dn,&N);create2(algo);roundrun(algo);)elseif(algo=3)(printf(nEnter process numbernH);scanf(d”,&N);create3 (algo);shorttask(algo);return;)else if(algo=,4,)exit(O);)main(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 处理机调度 课程设计报告 处理机 调度 课程设计 报告
限制150内