進(jìn)程調(diào)度算法操作系統(tǒng)課程設(shè)計(jì)_第1頁(yè)
進(jìn)程調(diào)度算法操作系統(tǒng)課程設(shè)計(jì)_第2頁(yè)
進(jìn)程調(diào)度算法操作系統(tǒng)課程設(shè)計(jì)_第3頁(yè)
進(jìn)程調(diào)度算法操作系統(tǒng)課程設(shè)計(jì)_第4頁(yè)
進(jìn)程調(diào)度算法操作系統(tǒng)課程設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩38頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

計(jì)算機(jī)科學(xué)與應(yīng)用系2操作系統(tǒng)課程設(shè)計(jì)一、實(shí)驗(yàn)?zāi)康耐ㄟ^(guò)優(yōu)先權(quán)法與輪轉(zhuǎn)調(diào)度算法的模擬加深對(duì)進(jìn)程概念和進(jìn)程調(diào)度過(guò)3、、、、、、、<3操作系統(tǒng)課程設(shè)計(jì)4=:^^_ready=:^^_ready-queue是否為NT1TY1YN更新新進(jìn)程就緒隊(duì)列進(jìn)程優(yōu)先數(shù),優(yōu)先數(shù)加1Y創(chuàng)建新進(jìn)程并加入到ready_queue中N5HLLtineCPUtineHLLtineCPUtineStatereadyreadyreadyrecitlySreadyreadyreadyready(4)在運(yùn)行過(guò)程中,當(dāng)遇到阻塞,則該進(jìn)程插入到阻塞隊(duì)列block_queuezz*Di\process\Dtsibug\pEocess-eieleascsclcctanHLn'1ThisThisJisaexampleForpi'iorit^pprocess:ingInputthenumbei*oFPCBtobestart■3IDIDpr*TL?ii*i1tyCPUt7xnieALLlrinteStzalzeDDpriorityIBi323碉Dpriority6操作系統(tǒng)課程設(shè)計(jì)1143t^unnxnsrTheprocessno1ifconpletedt銷昱殳』running->Destsrory期度開(kāi)始變遷1=ready->l^unnin^rrunnxngiheprocess:nu3ifcumplet-edf:Funitiriigf-->Destriory*ircad.^?>mnninsfThepracessno2iscomplelbedlfTheidleD^ocessidrunningT^iil:peadj/—>running變遷1=ready->l^unnin^3htsprocessnu4ifcumplet-edf乍肖艮殳:,本次調(diào)度結(jié)束。leascselcctamLE=runningrunniinsf—>DeEti*oyrunningFunniiriigfDestriOiry27g"D:\process\Debug\process口1DpriorityCPUtime0QIDppio^ityg"D:\process\Debug\process口1DpriorityCPUtime0QIDppio^ityk>0GFULjLi0ne0heidlepeocessIdmnnIng變遷3L=^eadyrunnjmgheprocessnolisbluckedf32heprocessno2ifcompleted?變遷i=ready->runmipffhep護(hù)曲te:生雪nu1~F1=readyiwigZ.exeHLLtime032ALLtineIFunning—>blockedFunffiiFanning-running—>Destrory銷毀土runningf■〉Dest^oi*^3If變遷running—>blockedblocked5487584574389574fgffffgfgf變遷1二readjy->runnioggfg389S43?89543758943?8954375(4)在運(yùn)行過(guò)程中,當(dāng)遇到阻塞,則該進(jìn)程插入到阻塞隊(duì)列block_queueStateStateStatereadyrenadyreadypenady(變遷丄二(變遷丄二?ady">running3322corniplei^edfcorniplei^edfheheidlepeocessidr-imning!+1::peadv一〉running異re^djy->ruvuniiogheprocessnu4IsblockedT21hepFoiCB&sno6ifCDimpleitKdfiruinnmg*runnIng'Desti^OFy8操作系統(tǒng)課程設(shè)計(jì)9操作系統(tǒng)課程設(shè)計(jì)材中介紹的算法做了哪些簡(jiǎn)單化處理優(yōu)先權(quán)模擬時(shí)優(yōu)先權(quán)是隨機(jī)產(chǎn)生,在實(shí)際的系統(tǒng)中,系統(tǒng)進(jìn)程的優(yōu)先權(quán)高于一列,每次調(diào)度時(shí),把CPU分配給首進(jìn)程,并令其用完時(shí),發(fā)出中斷請(qǐng)求,調(diào)度程序便據(jù)此信號(hào)來(lái)停止該進(jìn)程的執(zhí)行,并將其送到就緒隊(duì)列的末尾,如此反復(fù),就可以保證就緒隊(duì)列中的所有進(jìn)程在一個(gè)給定的時(shí)間最高優(yōu)先權(quán)調(diào)度算法,常用于批處理系統(tǒng)中,作為作業(yè)調(diào)度算法,也作為多種高的作業(yè),裝入內(nèi)存,當(dāng)用于進(jìn)程調(diào)度算法時(shí),該算法是把處理及分配給就緒隊(duì)列//process.cpp:Define//#include"stdafx.h"#include"stdio.h"#include"stdlib.h"操作系統(tǒng)課程設(shè)計(jì)intALLtime;intState;PCB*next;voidprint(PCB*pcb);/*輸出進(jìn)程屬性信息*/voidinsert();/*生成進(jìn)程屬性信息,插入進(jìn)程就緒隊(duì)列*/voidblock(PCB*pcb);/*調(diào)用destroy()將進(jìn)程插入阻塞隊(duì)列*/voidwakeup();/*喚醒進(jìn)程,插入就緒隊(duì)列*/voidproc_priority();/*優(yōu)先權(quán)調(diào)度算法模擬*/voidproc_loop();/*輪轉(zhuǎn)法調(diào)度算法模擬*/voidupdate(PCB*pcb);/*更新進(jìn)程信息*/voidpushback_queue(PCB*queue,PCB*item);/*將item插入到隊(duì)列的尾部*/voidinsert_queue(PCB*queue,PCB*item);/*將item插入到隊(duì)列中,使得插入后,voidsort_queue(PCB*&queue);/*對(duì)queue中的結(jié)點(diǎn)進(jìn)行排序,按照優(yōu)先級(jí)從大到小PCB*ready_queue,*block_queue,*idleprocess;/*就緒隊(duì)列,阻塞隊(duì)列及閑逛進(jìn)程指針變操作系統(tǒng)課程設(shè)計(jì)while(1)cout<<"\\**********PROCESS**********/"while(i){{}elseif(i==2){cout<<("\nThisisaexampleforroundrobinproces}{}}}}{cout<<("\nlDpriorityCPUtimeALLtimeState");while(temp!=NULL){cout<<"\n"<<temp_>ID<<""<<temp->CPUtime<<""<<temp->ALLtime;elseif(temp->State==1)cout<<("running");操作系統(tǒng)課程設(shè)計(jì)temp=temp->next;}}///////輸出進(jìn)程屬性信息voidprint(PCB*pcb){temp=pcb;{cout<<"\n"<<temp_>ID<<""<<temp->CPUtime<<""<<temp->ALLtime;elseif(temp->State==1)cout<<("running");}}///////將item插入到隊(duì)列中,使得插入后,隊(duì)列中按照優(yōu)先級(jí)從voidinsert_queue(PCB*queue,PCB*item){q=queue;p=q_>next;while(p!=0&&p->priority>=item->priority){}{}{}操作系統(tǒng)課程設(shè)計(jì)}voidpushback_queue(PCB*queue,PCB*item){q=queue,p=q_>next;while(p!=0){}}///////對(duì)queue中的結(jié)點(diǎn)進(jìn)行排序,按照優(yōu)先級(jí)從大到小voidsort_queue(PCB*&queue){while(queue->next){insert_queue(temp,p);}queue->next=temp->next;}///////生成進(jìn)程屬性信息,插入進(jìn)程就緒隊(duì)列,顯示進(jìn)程信息voidinsert(){PCB*newp=0;操作系統(tǒng)課程設(shè)計(jì)}////////生成n個(gè)進(jìn)程屬性信息,插入進(jìn)程就緒voidinsert(intn){insert();}{idleprocess=(PCB*)malloc(sizeof(PCB));idleprocess->ID=0;idleprocess->next=ready_queue->next;//ready_queue->next=idl//也可以假定初始時(shí)系統(tǒng)中只有一個(gè)idle進(jìn)程//輸入初始進(jìn)程的個(gè)數(shù){}cout<<("\nIDpriorityCPUtimeALLtimeState'n");insert();cout<<"*就緒隊(duì)列初始化成功"<<endl;}///////調(diào)用destroy()將進(jìn)程插入阻塞隊(duì)列{操作系統(tǒng)課程設(shè)計(jì){}cout<<"\nTheprocessnprint(pcb);pcb->next=block_queue->next;block_queue->ne}///////{///////{PCB*temp=pcb->next;while{temp_>priority++;temp=temp->next;}}//////////////{wakeup()if(block_queue->next==0)/*此時(shí)while(true){while(p&&rand()%20!=1){}{}}print(p);insert_queue(ready_queue,p);操作系統(tǒng)課程設(shè)計(jì)}...運(yùn)行進(jìn)程,隨機(jī)阻塞進(jìn)程、產(chǎn)生新進(jìn)程,插入就緒隊(duì)列{{insert_queue(ready_queue,pcb);print(pcb);}{pcb->priority=pcb->priorityprint(pcb);if(rand()%3==1)/*PCB不是閑逛進(jìn)程,滿足條件側(cè)阻塞此進(jìn)程{if(pcb->CPUtime-2<pcb->Aelse/*已執(zhí)行完畢,應(yīng)該銷毀進(jìn)程{cout<<"Theprocessno"<<pcb->ID<<"iscompleted!銷毀}}如果執(zhí)行完,則釋放,否則再次放入就緒隊(duì)列操作系統(tǒng)課程設(shè)計(jì){if(pcb->CPUtime>=pcb->ALLtime)/*釋放*/{cout<<"Theprocessno"<<pcb->ID<<"}{}}}更新就緒隊(duì)列的優(yōu)先級(jí)數(shù)更新就緒隊(duì)列的優(yōu)先級(jí)數(shù)*/if(rand()%5==1){insert(3);}if(rand()%7==1)wakeup();}///////運(yùn)行進(jìn)程,隨機(jī)阻塞進(jìn)程、產(chǎn)生新進(jìn)程,插入就緒隊(duì)列,喚醒阻塞進(jìn)程{{insert_queue(ready_queue,pcb);print(pcb);}{pcb->CPUtime=pcb->ALLprint(pcb);不是閑逛進(jìn)程,滿足條件側(cè)阻塞此進(jìn)程*/if(rand不是閑逛進(jìn)程,滿足條件側(cè)阻塞此進(jìn)程*/{_state=1;操作系統(tǒng)課程設(shè)計(jì){cout<<"Theprocessno"<<pc}}if(rand()%5==1){insert(3);}if(rand()%7==1)wakeup();}///////優(yōu)先權(quán)調(diào)度算法模擬voidproc_priority(){sort_queue(ready_queue);PCB*temp=0,*running=0;cout<<"*調(diào)度前:";for(;times<5;times++){running=ready_queue->next;ready_queue->next=running-cout<<"*調(diào)度開(kāi)始"<<endl;Run_priority(running);}cout<<"\n*本次調(diào)度結(jié)束。"<<endl;}///////輪轉(zhuǎn)調(diào)度算法模擬voidproc_loop(){PCB*temp=0,*running=0;cout<<"*調(diào)度前:";while(1){running=ready_queue->next;操作系統(tǒng)課程設(shè)計(jì)ready_queue->next=running-{times=times-running->ALLtime;〃每次運(yùn)行一個(gè)進(jìn)程減去ALLtime;{Run」oop(running);}elseif(_state)//如果運(yùn)行時(shí)被阻塞,則運(yùn)行2個(gè)時(shí)間單位{times=times+2;_state=0;cout<<"5487584574389574gfgfg38954378954375894378954375";}pushback_queue(block_queue,running);〃}{cout<<"\n*本次調(diào)度時(shí)間片到!";}}cout<<"\n*本次調(diào)度結(jié)束。"<<endl;}操作系統(tǒng)課程設(shè)計(jì)Linux進(jìn)程管理一、實(shí)驗(yàn)?zāi)康奈鲞M(jìn)程爭(zhēng)用資源的現(xiàn)象,學(xué)習(xí)解決進(jìn)程互斥的方法,了C++compiler宿寫,是C/C++語(yǔ)言的編譯器。因其后來(lái)可以多種語(yǔ)TASK_INTERRUPTIBLE可中斷阻塞):Linux將阻塞態(tài)劃分成TASK_UNINTERRUPTIBLETASK_STOPPEDTTASK_UNINTERRUPTIBL不可中斷喚醒):處于該狀態(tài)的進(jìn)程只有當(dāng)資源有效時(shí)被喚#include<stdio.h>{while(p1=fork()==-1);//操作系統(tǒng)課程設(shè)計(jì){while((p2==fork())==-1);〃創(chuàng)建子進(jìn)程if(p2==0)}}#include<stdio.h>{while(p仁fork()==-1);〃printf("daugheter%d\n",i);{while((p2==fork())==-1);〃創(chuàng)建子進(jìn)程printf("son%d\n",i);printf("parent%d\n",i);}}#include<stdio.h>#include<unistd.h>#include<sys/wait.h>#include<sys/stat.h>#include<sys/types.h>#include<fcntl.h>voidmain(){charstr[80];fd=open("myfile",O_RDWR|O_CR{}{操作系統(tǒng)課程設(shè)計(jì)}printf("Iamaparentprocess,mypidis%d\n",getid());printf("Pleaseinputastring:\n");write(fd,str,sizeof(str));{}{{}{}printf("\nIamaparentprocess,mypidis%d\n",getid());printf("Pleaseinputastring:\n");printf("%s\n",str);}}}父進(jìn)程捕捉鍵盤上來(lái)的中斷信號(hào)(即按Del鍵);當(dāng)捕捉到中斷信號(hào)后,父進(jìn)程用系統(tǒng)調(diào)#include<stdio.h>#in

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論