操作系統(tǒng)處理機(jī)調(diào)度實(shí)驗(yàn)報(bào)告_第1頁
操作系統(tǒng)處理機(jī)調(diào)度實(shí)驗(yàn)報(bào)告_第2頁
操作系統(tǒng)處理機(jī)調(diào)度實(shí)驗(yàn)報(bào)告_第3頁
操作系統(tǒng)處理機(jī)調(diào)度實(shí)驗(yàn)報(bào)告_第4頁
操作系統(tǒng)處理機(jī)調(diào)度實(shí)驗(yàn)報(bào)告_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

處理機(jī)調(diào)度算法實(shí)驗(yàn)報(bào)告學(xué)號(hào)姓名時(shí)間專業(yè)班級實(shí)驗(yàn)題目:處理機(jī)調(diào)度算法一、實(shí)驗(yàn)?zāi)康脑诹私獠僮飨到y(tǒng)的基礎(chǔ)上全面了解處理機(jī)調(diào)度算法的實(shí)現(xiàn)以及過程,詳細(xì)了解處理機(jī)調(diào)度算法的機(jī)制,充分了解調(diào)度的過程及狀態(tài),采用優(yōu)先數(shù)法進(jìn)程調(diào)度算法來模擬演示進(jìn)程調(diào)度二、實(shí)驗(yàn)內(nèi)容與步驟:了解進(jìn)程的三種狀態(tài)狀態(tài):ready、running、finish了解進(jìn)程需要的CPU時(shí)間以時(shí)間片為單位確定編寫一段程序#include<stdio.h>#include<stdlib.h>#defineP_NUM5#defineP_TIME50enumstate{ready,execute,block,finish};structpcbb{charname[4];intpriority;intcputime;intneedtime;intcount;enumstateprocess;structpcbb*next;};typedefstructpcbbpcb;voiddisplay_menu(){printf("CHOOSETHEALGORITHM:\n");printf("1PRIORITY\n");printf("2ROUNDROBIN\n");printf("3EXIT\n");}pcb*get_process(){pcb*q;pcb*p;pcb*t;inti=0;printf("inputnameandtime\n");while(i<P_NUM){q=(pcb*)malloc(sizeof(pcb));scanf("%s”,q->name);scanf("%d”,&q->needtime);q->cputime=0;q->priority=P_TIME-q->needtime;q->process=ready;q->next=NULL;if(i==0){p=q;t=q;}else{t->next=q;t=q;}i++;}returnp;}voidfree_process(pcb*p){pcb*q;while(p!=NULL){q=p;p=p->next;free(q);}}voiddisplay(pcb*p){printf("namecputimeneedtimeprioritystate\n");while(p){printf("%s”,p->name);printf("");printf("%d”,p->cputime);printf("");printf("%d”,p->needtime);printf("");printf("%d”,p->priority);printf("");switch(p->process){caseready:printf("ready\n");break;caseexecute:printf("execute\n");break;caseblock:printf("block\n");break;casefinish:printf("finish\n");break;}p=p->next;}}intprocess_finish(pcb*q){intbl=1;while(b1&&q){bl=b1&&q->needtime==0;q=q->next;}returnb1;}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(tp<q->priority&&q->process!=finish){tp=q->priority;t=q;}q=q->next;}if(t->needtime!=0){t->priority-=3;t->needtime--;t->process=execute;t->cputime++;}}voidpriority_cal(){pcb*p;p=get_process();intcpu=0;while(!process_finish(p)){cpu++;printf("cputime:%d\n”,cpu);cpuexe(p);display(p);sleep(2);}free_process(p);printf("Allprocesseshavefinished\n");}pcb*get_process_round(){pcb*q;pcb*p;pcb*t;inti=0;printf("inputnameandtime\n");while(i<P_NUM){q=(pcb*)malloc(sizeof(pcb));scanf("%s”,q->name);scanf("%d”,&q->needtime);q->cputime=0;q->count=0;q->process=ready;q->next=NULL;if(i==0){p=q;t=q;}else{t->next=q;t=q;}i++;}returnp;}voidcpu_round(pcb*q){if(q->needtime==1)q->cputime++;elseq->cputime+=2;q->needtime-=2;if(q->needtime<0){q->needtime=0;}q->count++;q->process=execute;}pcb*get_next(pcb*k,pcb*head){pcb*t;t=k;do{t=t->next;}while(t&&t->process==finish);if(t==NULL){t=head;while(t->next!=k&&t->process==finish){t=t->next;}}returnt;}voidset_state(pcb*p){while(p){if(p->needtime==0){p->process=finish;}if(p->process==execute){p->process=ready;}p=p->next;}}voiddisplay_round(pcb*p){printf("namecputimeneedtimecountstate\n");while(p){printf("%s”,p->name);printf("");printf("%d”,p->cputime);printf("");printf("%d”,p->needtime);printf("");printf("%d",p->count);printf("");switch(p->process){caseready:printf("ready\n");break;caseexecute:printf("execute\n");break;caseblock:printf("block\n");break;casefinish:printf("finish\n");break;}p=p->next;}}voidround_cal(){pcb*p;pcb*r;p=get_process_round();intcpu=0;r=p;while(!process_finish(p)){if(r->needtime==1)cpu+=1;elsecpu+=2;cpu_round(r);r=get_next(r,p);printf("cputime:%d\n”,cpu);display_round(p);set_state(p);sleep(2);}free_process(p);}main(){display_menu();intk;scanf("%d",&k);switch(k){case1:priority_cal();break;case2:round_cal();break;case3:break;default:printf("YOUHAVENOTCHOOSEANYALGORITHMS);}}運(yùn)行后結(jié)果如下:[root@rhel5hbzy~]#gcc-ochulijichuliji.c[root@rhel5hbzy~]#./mCHOOSETHEALGORITHM:PRIORITYROUNDROBINEXIT1inputnameandtimejing2aaaa8

bbbb5ffff4ggg6cputime:1namecputimeneedtimeprioritystatejing-1145executeaaaa*0842readybbbb20050finishffff20050finishggg0644readyrtyucputime:2namecputimeneedtimeprioritystatejing*2042executeaaaa*0842readybbbb20050finishffff20050finishggg0644ready5cputime:3namecputimeneedtimeprioritystatejing*2042finishaaaa*0842readybbbb20050finishffff20050finishggg1541execute2cputime:4namecputimeneedtimeprioritystatejing*2042finishaaaa,1739executebbbb20050finishffff20050finishggg1541readycputime:5namecputimeneedtimeprioritystatejing*2042finishaaaa1739readybbbb20050finishffff20050finishggg2438executecputime:6namecputimeneedtimeprioritystatejing*2042finishaaaa$2636executebbbb20050finish

ffff20050finishggg2438readycputime:7namecputimeneedtimeprioritystatejing*2042finishaaaa$2636readybbbb20050finishffff20050finishggg3335executecputime:8namecputimeneedtimeprioritystatejing*2042finishaaaa!3533executebbbb20050finishffff20050finishggg3335readycputime:9namecputimeneedtimeprioritystatejing*2042finishaaaa!3533readybbbb20050finishffff20050finishggg4232executecputime:10namecputimeneedtimeprioritystatejing*2042finishaaaa-4430executebbbb20050finishffff20050finishggg4232readycputime:11namecputimeneedtimeprioritystatejing*2042finishaaaa-4430readybbbb20050finishffff20050finishggg5129executecputime:12namecputimeneedtimeprioritystatejing*2042finishaaaa5327executebbbb20050finishffff20050finishggg5129ready

cputime:13namecputimeneedtimeprioritystatejing*2042finishaaaa5327readybbbb20050finishffff20050finishggg6026executecputime:14namecputimeneedtimeprioritystatejing*2042finishaaaa6224executebbbb20050finishffff20050finishggg6026finish3cputime:15namecputimeneedtimeprioritystatejing*2042finishaaaa7121executebbbb20050finishffff20050finishggg6026finishcputime:16namecputimeneedtimeprioritystatejing*2042finishaaaa8018executebbbb20050finishffff20050finishggg6026finishAllprocessesh

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論