模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語--附帶注釋_第1頁
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語--附帶注釋_第2頁
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語--附帶注釋_第3頁
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語--附帶注釋_第4頁
模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語--附帶注釋_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、題目:計(jì)算機(jī)操作系統(tǒng)模擬院系:信息學(xué)院專業(yè):計(jì)算機(jī)科學(xué)與技術(shù) 班級:2013級1班遼寧大學(xué)實(shí)驗(yàn)題目一:模擬進(jìn)程創(chuàng)建、終止、阻塞、喚醒原語一、題目類型:必做題目。二、實(shí)驗(yàn)?zāi)康模和ㄟ^設(shè)計(jì)并調(diào)試創(chuàng)建、終止、阻塞、喚醒原語功能,有助于對操作系統(tǒng)中進(jìn)程控制功能的理解,掌握操作系統(tǒng)模塊的設(shè)計(jì)方法和工作原理。三、實(shí)驗(yàn)環(huán)境:1、硬件:pc機(jī)及其兼容機(jī)。2、軟件:Windows XP,Turbo C或C+、VC+等。四、實(shí)驗(yàn)內(nèi)容:1、設(shè)計(jì)創(chuàng)建、終止、阻塞、喚醒原語功能函數(shù)。2、設(shè)計(jì)主函數(shù),采用菜單結(jié)構(gòu)(參見后面給出的流程圖)。3、設(shè)計(jì)“顯示隊(duì)列”函數(shù),目的能將就緒、阻塞隊(duì)列中的進(jìn)程信息顯示在屏幕上,以供隨時查看

2、各隊(duì)列中進(jìn)程的變化情況。五、實(shí)驗(yàn)要求:進(jìn)程名:用P1,P2標(biāo)識。優(yōu)先級:為實(shí)驗(yàn)題目二做準(zhǔn)備。運(yùn)行時間:為實(shí)驗(yàn)題目二做準(zhǔn)備。狀態(tài)為:就緒、運(yùn)行、阻塞,三種基本狀態(tài)。指針:指向下一個PCB。1、進(jìn)程PCB中應(yīng)包含以下內(nèi)容:進(jìn)程名優(yōu)先級運(yùn)行時間狀態(tài)指針2、系統(tǒng)總體結(jié)構(gòu):開始系統(tǒng)主菜單1創(chuàng)建2阻塞3喚醒4終止5顯示0退出請輸入您需要的功能(05):輸入選擇=?543210退出創(chuàng)建阻塞喚醒終止顯示結(jié)束另加實(shí)驗(yàn)二:模擬進(jìn)程調(diào)度功能/*PCB的組織方式:線性方式*/#include stdio.h#include string.h#include windows.htypedef structchar p_

3、name10;/進(jìn)程名char p_pro;/優(yōu)先級 1-3個級別 1.低 2.中 3.高char p_status;/運(yùn)行狀態(tài) 0.阻塞 1.運(yùn)行 2.就緒int p_runtime;/運(yùn)行時間int p_wait;/等待時間struct PCB *next;/指針,指向下一個PCBPCB;void Run(PCB *head)/任何時候保證程序里面至少有一個進(jìn)程在運(yùn)行PCB *p=head-next;/直接將P指向第一個結(jié)點(diǎn)while(p!=NULL)/遍歷一遍鏈表,將所有就緒隊(duì)列等待時間加1,防止前面結(jié)點(diǎn)因?yàn)閱拘延诌M(jìn)入運(yùn)行狀態(tài)if(p-p_status=2)p-p_wait+;/將等待時

4、間加1p=p-next;p=head-next;/將P重置在第一個結(jié)點(diǎn)while(p-p_status!=1 & p!=NULL)if(p-p_status=2)/防止線性鏈表前面的結(jié)點(diǎn)因?yàn)閺淖枞麊拘押笥诌M(jìn)入運(yùn)行狀態(tài)p-p_status=1;p-p_wait=2;if(p-p_status=1)/對上一個if進(jìn)行處理return;p=p-next;return;void Insert(PCB *head,PCB *temp)/插入鏈表函數(shù)PCB *p;p=head;/將頭結(jié)點(diǎn)保存起來while(p-next!=NULL)p=p-next;p-next=temp;temp-next=NULL;

5、int Check(PCB *head,PCB *temp)PCB *p=head;while(p-next)p=p-next;if(strcmp(p-p_name,temp-p_name)=0)return 0;return 1;void Create(PCB *head)/創(chuàng)建進(jìn)程函數(shù)int chk=0;PCB *temp;/申請臨時存儲空間,方便接受數(shù)據(jù)temp=(PCB *)malloc(sizeof(PCB);system(cls);printf(t-進(jìn)程創(chuàng)建-n);printf(n請輸入進(jìn)程名:);scanf(%s,temp-p_name);getchar();/*檢查進(jìn)程名稱,如

6、果相同則返回主界面*/chk=Check(head,temp);if(chk=0)printf(進(jìn)程隊(duì)列已有該名稱進(jìn)程,創(chuàng)建失敗,即將返回主界面.n);system(pause);return;printf(n請輸入進(jìn)程優(yōu)先級(1.低 2.中 3.高):);scanf(%c,&temp-p_pro);getchar();printf(n請輸入進(jìn)程運(yùn)行時間:);scanf(%d,&temp-p_runtime);getchar();temp-p_status=2;temp-p_wait=2;/*printf(n請輸入該進(jìn)程狀態(tài):);scanf(%c,&temp-p_status);getchar

7、();*/Insert(head,temp);/調(diào)用插入鏈表函數(shù)system(pause);Run(head);void Show(PCB *head)/顯示隊(duì)列進(jìn)程函數(shù)int ready=1,block=1,run=1;PCB *p=head,*q;system(cls);if(p-next=NULL)printf(目前系統(tǒng)中沒有進(jìn)程.請返回主界面創(chuàng)建進(jìn)程!n);system(pause);return;/*列出就緒隊(duì)列列表*/q=p-next;/指針指到第一個結(jié)點(diǎn)printf(n-就緒隊(duì)列-n);while(q)if(q-p_status=2)printf(%d)進(jìn)程名:%s,ready+

8、,q-p_name);printf( 進(jìn)程優(yōu)先級:%c,q-p_pro);printf( 進(jìn)程運(yùn)行時間:%d,q-p_runtime);printf( 進(jìn)程等待時間:%dn,q-p_wait);q=q-next;printf(n);/*列出運(yùn)行隊(duì)列列表*/q=p-next;/將指針重置到第一個結(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)先級:%c,q-p_pro);printf( 進(jìn)程運(yùn)行時間:%dn,q-p_runtime);/printf( 進(jìn)程已運(yùn)行時間:);q

9、=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)先級:%c,q-p_pro);printf( 進(jìn)程運(yùn)行時間:%d,q-p_runtime);printf( 進(jìn)程等待時間:%dn,q-p_wait);q=q-next;printf(n);printf(進(jìn)程顯示完畢.);system(pause);void Block(PCB *head)/阻塞進(jìn)程函數(shù)char name10;PCB *p=head

10、;/保護(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ì)列中無該進(jìn)程.n);system(pause);if(p-p_status=1)printf(n該進(jìn)程正在運(yùn)行.n);printf(n將該進(jìn)程放入阻塞隊(duì)列nn);system(pause);p-p_status=0;printf(n該進(jìn)程已經(jīng)被放入阻塞隊(duì)列n);system(p

11、ause);elseif(p-p_status=0)printf(n該進(jìn)程已在阻塞隊(duì)列中.n);system(pause);if(p-p_status=2)printf(n該進(jìn)程正在就緒隊(duì)列中.不可放入阻塞隊(duì)列n);system(pause);Run(head);void Delete(PCB *head,PCB *temp)/*head為鏈表頭結(jié)點(diǎn),temp為將要刪除的結(jié)點(diǎn)*/PCB *p=head,*q=temp-next;while(p-next!=temp)p=p-next;p-next=q;free(temp);void Stop(PCB *head)/終止進(jìn)程函數(shù)char name

12、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ì)列中無該進(jìn)程.n);system(pause);Delete(head,p);/調(diào)用刪除結(jié)點(diǎn)函數(shù)printf(n進(jìn)程終止成功n);system(pause);Run(head);void Wakeup(PCB *head)/喚醒進(jìn)程函數(shù)char name10;PCB

13、*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ì)列中無該進(jìn)程名稱.n);system(pause);return;if(p-p_status=0)printf(該進(jìn)程正在阻塞隊(duì)列中.n);printf(n將該進(jìn)程放回就緒隊(duì)列中n);system(pause);p-p_status=2;p-p_wait=2;print

14、f(n該進(jìn)程已經(jīng)被放入就緒隊(duì)列中n);system(pause);elseif(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);void prior_Sche(PCB *head)PCB *p=head-next,*temp=head-next;/保護(hù)頭結(jié)點(diǎn)p,temp為將要刪除的結(jié)點(diǎn)system(cls);if(p=NULL)printf(目前系統(tǒng)中沒有進(jìn)程.請返回主界面創(chuàng)建進(jìn)程!n);system(pause);return;w

15、hile(p)if(temp-p_pro p_pro)temp=p;/將此時優(yōu)先級最大的結(jié)點(diǎn)地址給臨時空間保存p=p-next;printf(nn);printf(經(jīng)過調(diào)度,此時程序中運(yùn)行的進(jìn)程是:n);printf(n 進(jìn)程名:%s,temp-p_name);printf( 進(jìn)程優(yōu)先級:%c,temp-p_pro);printf( 進(jìn)程運(yùn)行時間:%dn,temp-p_runtime);printf(n該進(jìn)程PCB顯示完畢!n);system(pause);Delete(head,temp);Run(head);void time_Sche(PCB *head)int ready=1;PCB

16、*p=head,*q,*temp=NULL;/保護(hù)頭結(jié)點(diǎn)p,temp為時間片用完將要刪除時,保護(hù)的臨時結(jié)點(diǎn)system(cls);if(p-next=NULL)printf(目前系統(tǒng)中沒有進(jìn)程.請返回主界面創(chuàng)建進(jìn)程!n);system(pause);return;/*列出就緒隊(duì)列列表*/q=p-next;/指針指到第一個結(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)先級:%c,q-p_pro);printf( 進(jìn)程運(yùn)行時間:%dn,q-p_runtime-);/pr

17、intf( 進(jìn)程已運(yùn)行時間:);if(q-p_runtime=0)temp=q;q=q-next;if(temp!=NULL)Delete(head,temp);printf(n);system(pause);void Scheduling(PCB *head)/調(diào)度程序while(1)int choose;system(cls);printf(1.優(yōu)先級調(diào)度n);printf(2.時間片調(diào)度n);printf(0.返回主菜單n);printf(n請輸入選項(xiàng):);scanf(%d,&choose);getchar();switch(choose)case 1:prior_Sche(head);

18、break;case 2:time_Sche(head);break;case 0: system(cls); return;break;default:printf(請輸入0-2的數(shù)字n);system(pause);system(cls);break;void Menu()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(nn);printf(t-完美分割線-n);printf(功能介紹:n);printf(阻塞:運(yùn)行-阻塞;處于運(yùn)行之外狀態(tài),給出提示信息;若進(jìn)程不存在也給出其他信息n);printf(

溫馨提示

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

評論

0/150

提交評論