操作系統(tǒng)實驗報告-時間片調度輪轉算法_第1頁
操作系統(tǒng)實驗報告-時間片調度輪轉算法_第2頁
操作系統(tǒng)實驗報告-時間片調度輪轉算法_第3頁
操作系統(tǒng)實驗報告-時間片調度輪轉算法_第4頁
操作系統(tǒng)實驗報告-時間片調度輪轉算法_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

操作系統(tǒng)實驗報告第一次實驗——時間片調度輪轉算法實驗時間:2014.11.7院系:計算機科學與技術學院班級:軟件2班實驗要求:實驗選題:時間片調度輪轉算法程序流程圖及程序代碼開始流程圖開始確定時間片大小確定時間片大小就緒隊列為空 空則等待就緒隊列為空 進行下一 否選擇隊首進程進行執(zhí)行一個時間片次選擇隊首進程進行執(zhí)行一個時間片執(zhí)行該進程運行完成 該進程運行完成 否 送到就緒隊列末尾送到就緒隊列末尾 是 程序代碼:#include<stdio.h>#include<conio.h>#defineN20typedefstructpcb{ charpname[N]; intruntime; intarrivetime; charstate; structpcb*next;}PCB;PCBhead_input;PCBhead_run;PCB*pcb_input;staticcharR='r',C='c';unsignedlongcurrent;voidinputprocess();intreadyprocess();intreadydata();intrunprocess();FILE*f;intreadyprocess(){ while(1) { if(readydata()==0) return1; else runprocess(); }}intreadydata(){ if(head_input.next==NULL) { if(head_run.next==NULL) return0; else return1; } PCB*p1,*p2,*p3; p1=head_run.next; p2=&head_run; while(p1!=NULL) { p2=p1; p1=p2->next; } p1=p2; p3=head_input.next; p2=&head_input; while(p3!=NULL) { if(((unsignedlong)p3->arrivetime<=current)&&(p3->state==R)) { printf("時間片為%8d(時間%4d);進程%s開始,\n",current,(current+500)/1000,p3->pname); fprintf(f,"時間片為%8d(時間%4d);進程%s開始,\n",current,(current+500)/1000,p3->pname); p2->next=p3->next; p3->next=p1->next; p1->next=p3; p3=p2; } p3=p3; p3=p3->next; } return1;}intrunprocess(){ PCB*p1,*p2; if(head_run.next==NULL) { current++; return1; } else { p1=head_run.next; p2=&head_run; while(p1!=NULL) { p1->runtime--; current++; if(p1->runtime<=0) { printf("時間片為%8d時間%4d進程%s結束.\n",current,(current+500)/1000,p1->pname); fprintf(f,"時間片為%8d時間%4d進程%s結束.\n",current,(current+500)/1000,p1->pname); p1->state=C; p2->next=p1->next; deletep1; p1=NULL; } else { p2=p1; p1=p2->next; } } return1; }}voidinputprocess(){ PCB*p1,*p2; intnum; unsignedlongmax=0; printf("請輸入進程的數(shù)量:"); fprintf(f,"請輸入進程的數(shù)量:"); scanf("%d",&num); fprintf(f,"%d\n",&num); p1=&head_input; p2=p1; p1->next=newPCB; p1=p1->next; for(inti=0;i<num;i++) { printf("請輸入第%d個進程的進程名:",i+1); fprintf(f,"請輸入第%d個進程的進程名:",i+1); scanf("%s",p1->pname); fprintf(f,"%s\n",p1->pname); printf("它的運行時間為:"); fprintf(f,"它的運行時間為:"); scanf("%d",&(p1->runtime)); fprintf(f,"%d\n",&(p1->runtime)); printf("它的到達時間為:"); fprintf(f,"它的到達時間為:"); scanf("%d",&(p1->arrivetime)); fprintf(f,"%d\n",&(p1->arrivetime)); p1->runtime=(p1->runtime)*1000; p1->arrivetime=(p1->arrivetime)*1000; p1->state=R; if((unsignedlong)(p1->arrivetime)>max) max=p1->arrivetime; p1->next=newPCB; p2=p1; p1=p1->next; } deletep1; p1=NULL; p2->next=NULL;}voidmain(){ f=fopen("result.txt","w"); printf("時間1=1000時間片\n"); fprintf(f,"\ntime1=1000timeslice\n"); current=0; inputprocess(); readyprocess(); getch(); fclose(f);}PCB數(shù)據(jù)結構typedefstructpcb{ charpname[

溫馨提示

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

評論

0/150

提交評論