欢迎来到天天文库
浏览记录
ID:61488597
大小:22.00 KB
页数:5页
时间:2021-02-05
《操作系统进程管理程序.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#include#include#include#defineP_NUM5#defineP_TIME50enumstate{ready,execute,block,finish};structpcb{charname[4];intpriority;intcputime;intneedtime;intcount;intround;stateprocess;pcb*next;};pcb*g
2、et_process();pcb*get_process(){pcb*q;pcb*t;pcb*p;inti=0;cout<<"inputnameandtime"<>q->name;cin>>q->needtime;q->cputime=0;q->priority=P_TIME-q->needtime;q->process=ready;q->next=NULL;if(i==0){p=q;t=q;
3、}else{t->next=q;t=q;}i++;}//whilereturnp;}voiddisplay(pcb*p){cout<<"name"<<""<<"cputime"<<""<<"needtime"<<""<<"priority"<<""<<"state"<name;cout<<"";cout<cputime;cout<<"";cout<needtime;cout<<"";cout<priority;cout<<"";switc
4、h(p->process){caseready:cout<<"ready"<next;}}intprocess_finish(pcb*q){intbl=1;while(bl&&q){bl=bl&&q->needtime==0;q=q->next;}r
5、eturnbl;}voidcpuexe(pcb*q){pcb*t=q;inttp=0;while(q){if(q->process!=finish){q->process=ready;if(q->needtime==0){q->process=finish;}}if(tppriority&&q->process!=finish){tp=q->priority;t=q;}q=q->next;}if(t->needtime!=0){t->priority-=3;t->needtime--;t->proce
6、ss=execute;t->cputime++;}}voidpriority_cal(){pcb*p;p=get_process();intcpu=0;while(!process_finish(p)){cpu++;cout<<"cputime:"<7、GORITHM:"<>q->name;cin>>q->needtime;q->cputime=8、0;q->round=0;q->count=0;q->process=ready;q->next=NULL;if(i==0){p=q;t=q;}else{t->next=q;t=q;}i++;}//whilereturnp;}voidcpu_round(pcb*q){q->cputime+=2;q->needtime-=2;if(q->needtime<0){q->needtime=0;}q->co
7、GORITHM:"<>q->name;cin>>q->needtime;q->cputime=
8、0;q->round=0;q->count=0;q->process=ready;q->next=NULL;if(i==0){p=q;t=q;}else{t->next=q;t=q;}i++;}//whilereturnp;}voidcpu_round(pcb*q){q->cputime+=2;q->needtime-=2;if(q->needtime<0){q->needtime=0;}q->co
此文档下载收益归作者所有