模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語(yǔ)-附帶注釋_第1頁(yè)
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語(yǔ)-附帶注釋_第2頁(yè)
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語(yǔ)-附帶注釋_第3頁(yè)
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語(yǔ)-附帶注釋_第4頁(yè)
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語(yǔ)-附帶注釋_第5頁(yè)
已閱讀5頁(yè),還剩22頁(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ìn)程創(chuàng)建、終止、阻塞、喚醒原語(yǔ)--附帶注釋題目:計(jì)算機(jī)操作系統(tǒng)模擬院系:信息學(xué)院專(zhuān)業(yè):計(jì)算機(jī)科學(xué)與技術(shù)班級(jí):2013級(jí)1班遼寧大學(xué)

實(shí)驗(yàn)題目一:模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語(yǔ)一、題目類(lèi)型:必做題目。二、實(shí)驗(yàn)?zāi)康模和ㄟ^(guò)設(shè)計(jì)并調(diào)試創(chuàng)建、終止、阻塞、喚醒原語(yǔ)功能,有助于對(duì)操作系統(tǒng)中進(jìn)程控制功能的理解,掌握操作系統(tǒng)模塊的設(shè)計(jì)方法和工作原理。三、實(shí)驗(yàn)環(huán)境:1、硬件:pc機(jī)及其兼容機(jī)。2、軟件:WindowsXP,TurboC或C++、VC++等。四、實(shí)驗(yàn)內(nèi)容:1、設(shè)計(jì)創(chuàng)建、終止、阻塞、喚醒原語(yǔ)功能函數(shù)。2、設(shè)計(jì)主函數(shù),采用菜單結(jié)構(gòu)(參見(jiàn)后面給出的流程圖)。3、設(shè)計(jì)“顯示隊(duì)列”函數(shù),目的能將就緒、阻塞隊(duì)列中的進(jìn)程信息顯示在屏幕上,以供隨時(shí)查看各隊(duì)列中進(jìn)程的變化情況。五、實(shí)驗(yàn)要求:進(jìn)程名:用P1,P2標(biāo)識(shí)。優(yōu)先級(jí):為實(shí)驗(yàn)題目二做準(zhǔn)備。運(yùn)行時(shí)間:為實(shí)驗(yàn)題目二做準(zhǔn)備。進(jìn)程名:用P1,P2標(biāo)識(shí)。優(yōu)先級(jí):為實(shí)驗(yàn)題目二做準(zhǔn)備。運(yùn)行時(shí)間:為實(shí)驗(yàn)題目二做準(zhǔn)備。狀態(tài)為:就緒、運(yùn)行、阻塞,三種基本狀態(tài)。指針:指向下一個(gè)PCB。進(jìn)程名優(yōu)先級(jí) { p->p_status='1'; p->p_wait=2; } if(p->p_status=='1')//對(duì)上一個(gè)if進(jìn)行處理 { return; } p=p->next; } return;}voidInsert(PCB*head,PCB*temp)//插入鏈表函數(shù){ PCB*p; p=head;//將頭結(jié)點(diǎn)保存起來(lái) while(p->next!=NULL) { p=p->next; } p->next=temp; temp->next=NULL;}intCheck(PCB*head,PCB*temp){ PCB*p=head; while(p->next) { p=p->next; if(strcmp(p->p_name,temp->p_name)==0) return0; } return1;}voidCreate(PCB*head)//創(chuàng)建進(jìn)程函數(shù){ intchk=0; PCB*temp;//申請(qǐng)臨時(shí)存儲(chǔ)空間,方便接受數(shù)據(jù) temp=(PCB*)malloc(sizeof(PCB)); system("cls"); printf("\t----------進(jìn)程創(chuàng)建-----------\n"); printf("\n請(qǐng)輸入進(jìn)程名:"); scanf("%s",temp->p_name); getchar(); /*檢查進(jìn)程名稱,如果相同則返回主界面*/ chk=Check(head,temp); if(chk==0) { printf("進(jìn)程隊(duì)列已有該名稱進(jìn)程,創(chuàng)建失敗,即將返回主界面.\n"); system("pause"); return; } printf("\n請(qǐng)輸入進(jìn)程優(yōu)先級(jí)(1.低2.中3.高):"); scanf("%c",&temp->p_pro); getchar(); printf("\n請(qǐng)輸入進(jìn)程運(yùn)行時(shí)間:"); scanf("%d",&temp->p_runtime); getchar(); temp->p_status='2'; temp->p_wait=2; /* printf("\n請(qǐng)輸入該進(jìn)程狀態(tài):"); scanf("%c",&temp->p_status); getchar(); */ Insert(head,temp);//調(diào)用插入鏈表函數(shù) system("pause"); Run(head);}voidShow(PCB*head)//顯示隊(duì)列進(jìn)程函數(shù){ intready=1,block=1,run=1; PCB*p=head,*q; system("cls"); if(p->next==NULL) { printf("目前系統(tǒng)中沒(méi)有進(jìn)程.請(qǐng)返回主界面創(chuàng)建進(jìn)程!\n"); system("pause"); return; } /*列出就緒隊(duì)列列表*/ q=p->next;//指針指到第一個(gè)結(jié)點(diǎn) printf("\n--就緒隊(duì)列--\n"); while(q) { if(q->p_status=='2') { printf("%d)進(jìn)程名:%s",ready++,q->p_name); printf("進(jìn)程優(yōu)先級(jí):%c",q->p_pro); printf("進(jìn)程運(yùn)行時(shí)間:%d",q->p_runtime); printf("進(jìn)程等待時(shí)間:%d\n",q->p_wait); } q=q->next; } printf("\n"); /*列出運(yùn)行隊(duì)列列表*/ q=p->next;//將指針重置到第一個(gè)結(jié)點(diǎn) printf("\n--運(yùn)行隊(duì)列--\n"); while(q) { if(q->p_status=='1') { printf("%d)進(jìn)程名:%s",run++,q->p_name); printf("進(jìn)程優(yōu)先級(jí):%c",q->p_pro); printf("進(jìn)程運(yùn)行時(shí)間:%d\n",q->p_runtime); //printf("進(jìn)程已運(yùn)行時(shí)間:"); } q=q->next; } printf("\n"); /*列出阻塞隊(duì)列列表*/ q=p->next; printf("\n--阻塞隊(duì)列--\n"); while(q) { if(q->p_status=='0') { printf("%d)進(jìn)程名:%s",block++,q->p_name); printf("進(jìn)程優(yōu)先級(jí):%c",q->p_pro); printf("進(jìn)程運(yùn)行時(shí)間:%d",q->p_runtime); printf("進(jìn)程等待時(shí)間:%d\n",q->p_wait); } q=q->next; } printf("\n"); printf("進(jìn)程顯示完畢."); system("pause");}voidBlock(PCB*head)//阻塞進(jìn)程函數(shù){ charname[10]; PCB*p=head;//保護(hù)頭結(jié)點(diǎn) system("cls"); printf("\t----------阻塞進(jìn)程-----------\n"); printf("\n輸入你要放入阻塞隊(duì)列的進(jìn)程名稱:"); scanf("%s",name); getchar(); p=p->next; while(p) { if(strcmp(p->p_name,name)==0) break; p=p->next; } if(!p) { printf("\n隊(duì)列中無(wú)該進(jìn)程.\n"); system("pause"); } if(p->p_status=='1') { printf("\n該進(jìn)程正在運(yùn)行.\n"); printf("\n將該進(jìn)程放入阻塞隊(duì)列\(zhòng)n\n"); system("pause"); p->p_status='0'; printf("\n該進(jìn)程已經(jīng)被放入阻塞隊(duì)列\(zhòng)n"); system("pause"); } else { if(p->p_status=='0') { printf("\n該進(jìn)程已在阻塞隊(duì)列中.\n"); system("pause"); } if(p->p_status=='2') { printf("\n該進(jìn)程正在就緒隊(duì)列中.不可放入阻塞隊(duì)列\(zhòng)n"); system("pause"); } } Run(head);}voidDelete(PCB*head,PCB*temp)/*head為鏈表頭結(jié)點(diǎn),temp為將要?jiǎng)h除的結(jié)點(diǎn)*/{ PCB*p=head,*q=temp->next; while(p->next!=temp) { p=p->next; } p->next=q; free(temp);}voidStop(PCB*head)//終止進(jìn)程函數(shù){ charname[10]; PCB*p=head; system("cls"); printf("\t----------終止進(jìn)程-----------\n"); printf("\n輸入你要終止的進(jìn)程名稱:"); scanf("%s",name); getchar(); p=p->next; while(p) { if(strcmp(p->p_name,name)==0) break; p=p->next; } if(!p) { printf("進(jìn)程隊(duì)列中無(wú)該進(jìn)程.\n"); system("pause"); } Delete(head,p);//調(diào)用刪除結(jié)點(diǎn)函數(shù) printf("\n進(jìn)程終止成功\n"); system("pause"); Run(head);}voidWakeup(PCB*head)//喚醒進(jìn)程函數(shù){ charname[10]; PCB*p=head;//保護(hù)頭結(jié)點(diǎn) system("cls"); printf("\t----------喚醒進(jìn)程-----------\n"); printf("\n輸入你要喚醒的進(jìn)程名稱:"); scanf("%s",name); getchar(); p=p->next; while(p) { if(strcmp(p->p_name,name)==0) break; p=p->next; } if(!p) { printf("阻塞隊(duì)列中無(wú)該進(jìn)程名稱.\n"); system("pause"); return; } if(p->p_status=='0') { printf("該進(jìn)程正在阻塞隊(duì)列中.\n"); printf("\n將該進(jìn)程放回就緒隊(duì)列中\(zhòng)n"); system("pause"); p->p_status='2'; p->p_wait=2; printf("\n該進(jìn)程已經(jīng)被放入就緒隊(duì)列中\(zhòng)n"); system("pause"); } else { if(p->p_status=='1') { printf("\n該進(jìn)程正在運(yùn)行.不可喚醒\n"); system("pause"); } if(p->p_status=='2') { printf("\n該進(jìn)程正在就緒隊(duì)列中.不可喚醒\n"); system("pause"); } }}voidprior_Sche(PCB*head){ PCB*p=head->next,*temp=head->next;//保護(hù)頭結(jié)點(diǎn)p,temp為將要?jiǎng)h除的結(jié)點(diǎn) system("cls"); if(p==NULL) { printf("目前系統(tǒng)中沒(méi)有進(jìn)程.請(qǐng)返回主界面創(chuàng)建進(jìn)程!\n"); system("pause"); return; } while(p) { if(temp->p_pro<p->p_pro) { temp=p;//將此時(shí)優(yōu)先級(jí)最大的結(jié)點(diǎn)地址給臨時(shí)空間保存 } p=p->next; } printf("\n\n"); printf("經(jīng)過(guò)調(diào)度,此時(shí)程序中運(yùn)行的進(jìn)程是:\n"); printf("\n進(jìn)程名:%s",temp->p_name); printf("進(jìn)程優(yōu)先級(jí):%c",temp->p_pro); printf("進(jìn)程運(yùn)行時(shí)間:%d\n",temp->p_runtime); printf("\n該進(jìn)程PCB顯示完畢!\n"); system("pause"); Delete(head,temp); Run(head);}voidtime_Sche(PCB*head){ intready=1; PCB*p=head,*q,*temp=NULL;//保護(hù)頭結(jié)點(diǎn)p,temp為時(shí)間片用完將要?jiǎng)h除時(shí),保護(hù)的臨時(shí)結(jié)點(diǎn) system("cls"); if(p->next==NULL) { printf("目前系統(tǒng)中沒(méi)有進(jìn)程.請(qǐng)返回主界面創(chuàng)建進(jìn)程!\n"); system("pause"); return; } /*列出就緒隊(duì)列列表*/ q=p->next;//指針指到第一個(gè)結(jié)點(diǎn) printf("\n--就緒隊(duì)列--\n"); while(q) { if(q->p_status=='2') { printf("%d)進(jìn)程名:%s",ready++,q->p_name); printf("進(jìn)程優(yōu)先級(jí):%c",q->p_pro); printf("進(jìn)程運(yùn)行時(shí)間:%d\n",q->p_runtime--); //printf("進(jìn)程已運(yùn)行時(shí)間:"); } if(q->p_runtime==0) { temp=q; } q=q->next; } if(temp!=NULL) { Delete(head,temp); } printf("\n"); system("pause");}voidScheduling(PCB*head)//調(diào)度程序{ while(1) { intchoose; system("cls"); printf("1.優(yōu)先級(jí)調(diào)度\n"); printf("2.時(shí)間片調(diào)度\n"); printf("0.返回主菜單\n"); printf("\n請(qǐng)輸入選項(xiàng):"); scanf("%d",&choose); getchar(); switch(choose) { case1:prior_Sche(head);break; case2:time_Sche(head);break; case0:{system("cls");return;}break; default:{printf("請(qǐng)輸入0-2的數(shù)字\n");system("pause");system("cls");}break; } }}voidMenu(){ printf("\t----------模擬系統(tǒng)進(jìn)程創(chuàng)建、終止、阻塞、喚醒-----------"); printf("\n"); printf("1.進(jìn)程創(chuàng)建\n"); printf("2.阻塞進(jìn)程\n"); printf("3.喚醒進(jìn)程\n"); printf("4.終止進(jìn)程\n"); printf("5.顯示進(jìn)程\n"); printf("6.調(diào)度進(jìn)程\n"); printf("0.退出\n"); printf("\n\n"); printf("\t------------------------完美分割線---------------------\n"); printf("功能介紹:\n"); printf("阻塞:運(yùn)行->阻塞;處于運(yùn)行之外狀態(tài),給出提示信息;若進(jìn)程不存在也給出其他信息\n"); printf("喚醒:根據(jù)輸入的進(jìn)程名結(jié)束進(jìn)

溫馨提示

  • 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)論