




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、 操作系統(tǒng)實驗(3) 實驗題目:存 儲 管 理 實 驗課程名稱:操 作 系 統(tǒng) 學(xué) 院:管 理 學(xué) 院 專業(yè)班級: 學(xué) 號(1): 姓 名(1): 學(xué) 號(2): 姓 名(2): 任課教師: 2010年05月06日學(xué)院:管 理 學(xué) 院 班級: 組員: 組員: 評定: 實驗題目:存儲管理實驗(1) 實驗?zāi)康模和ㄟ^編寫和調(diào)試存儲管理的模擬程序以加深對存儲管理方案的 理解。(2)實驗內(nèi)容:設(shè)計一個可變式分區(qū)分配的存儲管理方案。并模擬實現(xiàn)分區(qū)的 分配和回收過程。 對分區(qū)的管理法可以是下面三種算法之一: 首次適應(yīng)算法 循環(huán)首次適應(yīng)算法 最佳適應(yīng)算法(3) 源代碼(含注釋):首次適應(yīng)算法(ff):#inc
2、lude#include#include#includestruct nc int n; /*內(nèi)存號*/ int rl; /*內(nèi)存容量*/ int sdz; /*首地址*/ struct nc *next;*head;struct pcb int num; /*進程號*/ char name10; /*進程名*/ int nv; /*進程大小*/ int itime; /*進程進入內(nèi)存時間*/ int ncn; /*裝入的內(nèi)存號*/ int sdzv; /*存入內(nèi)存的首地址*/ int ntime; /*進程運行總時間*/ int rtime; /*進程運行時間*/ char state; /
3、*進程狀態(tài)*/ struct pcb *link;*tou;int all; /*進程總數(shù)變量*/int tim=0; /*當前時間變量*/void innc() /*將進程裝入內(nèi)存*/struct nc *md;struct pcb *xx;xx=tou;while(xx!=null)if(xx-ncn=0&(xx-itimeitimerl=xx-nv) xx-ncn=md-n; xx-sdzv=md-sdz; md-sdz=md-sdz+xx-nv; md-rl=md-rl-xx-nv; goto leep; md=md-next; leep:if(md=null) printf(the
4、process %s cant into ncn,xx-name); xx=xx-link;void sort()struct pcb *p1,*p2;p1=p2=tou;while(p1-link!=null) if(p1-link)-itimelink)-ncn!=0) tou=p2=p1; while(p1-link!=null) p1=p1-link; p1-link=tou;tou=tou-link;p2-link=null; else p1=p1-link; void creatnc() /*創(chuàng)建內(nèi)存鏈表*/struct nc *p1,*p2;int ncx,ncy;printf(
5、input the numeber of nc(input 0 to end):);scanf(%d,&ncx);p2=(struct nc*)malloc(sizeof(struct nc);p1-next=null;head=p2=p1;while(ncx0) p1-n=ncx; printf(input the large of nc:); scanf(%d,&p1-rl); printf(input the sdz of nc:); scanf(%d,&ncy); p1-sdz=ncy; p2-next=p1;p2=p1; printf(input the numeber of nc(
6、input 0 to end):); scanf(%d,&ncx); if(ncxnext=null; void creatpcb() /*創(chuàng)建進程鏈表*/struct pcb *p1,*p2;char ch;int i;printf(how many pcb you want to creat:);scanf(%d,&all);for(i=0;ilink=null; if(i=0) tou=p2=p1; printf(input the name of the no.%d pcb:,i); scanf(%s,p1-name); printf(input the large of the pc
7、b:); scanf(%d,&p1-nv); printf(input the time of the pcb into the nc:); scanf(%d,&p1-itime); printf(input the time of the pcb running:); scanf(%d,&p1-ntime); p1-state=w;p1-rtime=0;p1-ncn=0; if(i!=0) p2-link=p1;p2=p1; innc();if(tou-itimetim) sort();disp(pcb * pr) /*建立進程顯示函數(shù),用于顯示當前進程*/ printf(n qname t
8、 state t ncn t ndtime t runtime n); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ncn); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); printf(n); void check() /* 建立進程查看函數(shù) */ struct pcb* pr; pr=tou-link;printf(now the time is:%dn ,tim);printf(n the process that running now is:%s,tou-name
9、); /*顯示當前運行進程*/ if(tou-itimencn!=0) disp(tou); printf(n the ready team are:n); /*顯示就緒隊列狀態(tài)*/ while(pr!=null) if(pr-itimelink; void look()struct nc *pr;printf(n num t rl t sdz t n);pr=head;while(pr!=null) printf(%d t %d t %d tn,pr-n,pr-rl,pr-sdz); pr=pr-next;void freenc() /*內(nèi)存釋放*/struct nc *dnc;struct
10、 pcb *pr,*pl;dnc=head;pr=pl=tou;while(dnc!=null) if(dnc-n=pr-ncn) break; else dnc=dnc-next; if(pr-sdzv+pr-nv=dnc-n) dnc-n=pr-sdzv;dnc-rl=dnc-rl+pr-nv;else while(pl!=null) if(pl-ncn=dnc-n) if(pr-sdzv+pr-nvsdzv) pl-sdzv=pl-sdzv-pr-nv; pl=pl-link; dnc-sdz=dnc-sdz-pr-nv;dnc-rl=pr-nv; void destory()struc
11、t pcb *pr;freenc();pr=tou;if(pr-link!=null) tou=tou-link; free(pr); all-; if(tou-itimetim) sort(); else free(pr); all=0;void running()struct pcb *pr;pr=tou;pr-rtime=pr-rtime+1;pr-state=r;tim+;check();look();if(pr-rtime=pr-ntime) destory();else pr-state=w;innc();sort();void main()clrscr();creatnc();c
12、reatpcb();check();while(all0)running(); printf(press any key to continuen); getch();printf(the process are finishedn);循環(huán)首次適應(yīng)算法(nf):#include#include#include#includestruct nc int n; /*內(nèi)存號*/ int rl; /*內(nèi)存容量*/ int sdz; /*首地址*/ struct nc *next;*head;struct pcb int num; /*進程號*/ char name10; /*進程名*/ int nv;
13、 /*進程大小*/ int itime; /*進程進入內(nèi)存時間*/ int ncn; /*裝入的內(nèi)存號*/ int sdzv; /*存入內(nèi)存的首地址*/ int ntime; /*進程運行總時間*/ int rtime; /*進程運行時間*/ char state; /*進程狀態(tài)*/ struct pcb *link;*tou;int all; /*進程總數(shù)變量*/int tim=0; /*當前時間變量*/void innc() /*將進程裝入內(nèi)存*/struct pcb *xx;xx=tou;while(xx!=null) if(xx-itimerlxx-nv) head-rl=head-r
14、l-xx-nv;xx-sdzv=head-sdz;head-sdz=head-sdz+xx-nv;xx-ncn=head-n;break; head=head-next; if(head=null) printf(the pcb cant enter nc as the nc no rl); xx=xx-link; void sort()struct pcb *p1,*p2;p1=p2=tou;while(p1!=null) if(p1-link)-itimelink!=null) p1=p1-link; p1-link=tou;tou=tou-link;p2-link=null; else
15、p1=p1-link; void creatnc() /*創(chuàng)建內(nèi)存鏈表*/struct nc *p1,*p2;int ncx,ncy;printf(input the numeber of nc(input 0 to end):);scanf(%d,&ncx);head=p1=p2=(struct nc*)malloc(sizeof(struct nc);while(ncx0) p1-n=ncx; printf(input the large of nc(input 0 to end):); scanf(%d,&p1-rl); printf(input the sdz of nc:); sca
16、nf(%d,&ncy); p1-sdz=ncy; p2-next=p1;p2=p1; printf(input the numeber of nc(input 0 to end):); scanf(%d,&ncx); p1=(struct nc*)malloc(sizeof(struct nc); p2-next=head;void creatpcb() /*創(chuàng)建進程鏈表*/struct pcb *p1,*p2;char ch;int i;printf(how many pcb you want to creat:);scanf(%d,&all);for(i=0;ilink=null; if(
17、i=0) tou=p2=p1; printf(input the name of the no.%d pcb:,i); scanf(%s,p1-name); printf(input the large of the pcb:); scanf(%d,p1-nv); printf(input the time of the pcb into the nc:); scanf(%d,&p1-itime); printf(input the time of the pcb running:); scanf(%d,&p1-ntime); p1-state=w;p1-rtime=0; p2-link=p1
18、;p2=p1; innc();if(tou-itimetim) sort();disp(pcb * pr) /*建立進程顯示函數(shù),用于顯示當前進程*/ printf(n qname t state t ncn t ndtime t runtime n); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ncn); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); printf(n); check() /* 建立進程查看函數(shù) */ pcb* pr; pr=tou-link;print
19、f(now the time is:%dn ,tim);printf(n the process that running now is:%s,tou-name); /*顯示當前運行進程*/ if(tou-itimeitimelink; void freenc() /*內(nèi)存釋放*/struct nc *dnc;struct pcb *pr,*pl;dnc=head;pr=pl=tou;while(dnc!=null) if(dnc-n=pr-ncn) break; else dnc=dnc-next; if(pr-sdzv+pr-nv=dnc-n) dnc-n=pr-sdzv;dnc-rl=d
20、nc-rl+pr-nv;else while(pl!=null) if(pl-ncn=dnc-n) if(pr-sdzv+pr-nvsdzv) pl-sdzv=pl-sdzv-pr-nv; pl=pl-link; dnc-n=dnc-n-pr-nv;dnc-rl=pr-nv; void destory()struct pcb *pr;freenc();pr=tou;if(pr-link!=null) tou=tou-link; free(pr); all-; if(tou-itimetim) sort(); else free(pr); all=0;void running()struct p
21、cb *pr;pr=tou;pr-rtime=pr-rtime+1;pr-state=r;tim+;check();if(pr-rtime=pr-ntime) destory();else pr-state=w;sort();innc();void main()char ch;clrscr();creatnc();creatpcb();check();while(all0)running();ch=getchar();printf(the process are finishedn);最佳適應(yīng)算法(bf):#include#include#include#includestruct nc in
22、t n; /*內(nèi)存號*/ int rl; /*內(nèi)存容量*/ int sdz; /*首地址*/ struct nc *next;*head;struct pcb int num; /*進程號*/ char name10; /*進程名*/ int nv; /*進程大小*/ int itime; /*進程進入內(nèi)存時間*/ int ncn; /*裝入的內(nèi)存號*/ int sdzv; /*存入內(nèi)存的首地址*/ int ntime; /*進程運行總時間*/ int rtime; /*進程運行時間*/ char state; /*進程狀態(tài)*/ struct pcb *link;*tou;int all; /
23、*進程總數(shù)變量*/int tim=0; /*當前時間變量*/void innc() /*將進程裝入內(nèi)存*/struct nc *md;struct pcb *xx;xx=tou;md=head;while(xx!=null) if(xx-itimerlxx-nv) md-rl=md-rl-xx-nv;xx-sdzv=md-sdz;md-sdz=md-sdz+xx-nv;xx-ncn=md-n;break; md=md-next; if(md=null) printf(the pcb cant enter nc as the nc no rl); xx=xx-link; void sort()s
24、truct pcb *p1,*p2;p1=p2=tou;while(p1!=null) if(p1-link)-itimelink!=null) p1=p1-link; p1-link=tou;tou=tou-link;p2-link=null; else p1=p1-link; void ncsort()struct nc *p1,*p2,*p3;int i=0,j;p1=head;while(p1!=null) i+; p1=p1-next;for(j=0;jnext; while(p2-next!=null) if(p1-rlp2-rl) p3=p1;p1=p2;p2=p3; p1=p1
25、-next;p2=p1-next; void creatnc() /*創(chuàng)建內(nèi)存鏈表*/struct nc *p1,*p2;int ncx,ncy;printf(input the numeber of nc(input 0 to end):);scanf(%d,&ncx);head=p1=p2=(struct nc*)malloc(sizeof(struct nc);while(ncx0) p1-n=ncx; printf(input the large of nc(input 0 to end):); scanf(%d,&p1-rl); printf(input the sdz of nc:
26、); scanf(%d,&ncy); p1-sdz=ncy; p2-next=p1;p2=p1; printf(input the numeber of nc(input 0 to end):); scanf(%d,&ncx); p1=(struct nc*)malloc(sizeof(struct nc); ncsort();void creatpcb() /*創(chuàng)建進程鏈表*/struct pcb *p1,*p2;char ch;int i;printf(how many pcb you want to creat:);scanf(%d,&all);for(i=0;ilink=null; i
27、f(i=0) tou=p2=p1; printf(input the name of the no.%d pcb:,i); scanf(%s,p1-name); printf(input the large of the pcb:); scanf(%d,p1-nv); printf(input the time of the pcb into the nc:); scanf(%d,&p1-itime); printf(input the time of the pcb running:); scanf(%d,&p1-ntime); p1-state=w;p1-rtime=0; p2-link=
28、p1;p2=p1; innc();if(tou-itimetim) sort();disp(pcb * pr) /*建立進程顯示函數(shù),用于顯示當前進程*/ printf(n qname t state t ncn t ndtime t runtime n); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ncn); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); printf(n); check() /* 建立進程查看函數(shù) */ pcb* pr; pr=tou-link;pri
29、ntf(now the time is:%dn ,tim);printf(n the process that running now is:%s,tou-name); /*顯示當前運行進程*/ if(tou-itimeitimelink; void freenc() /*內(nèi)存釋放*/struct nc *dnc;struct pcb *pr,*pl;dnc=head;pr=pl=tou;while(dnc!=null) if(dnc-n=pr-ncn) break; else dnc=dnc-next; if(pr-sdzv+pr-nv=dnc-n) dnc-n=pr-sdzv;dnc-rl
30、=dnc-rl+pr-nv;else while(pl!=null) if(pl-ncn=dnc-n) if(pr-sdzv+pr-nvsdzv) pl-sdzv=pl-sdzv-pr-nv; pl=pl-link; dnc-n=dnc-n-pr-nv;dnc-rl=pr-nv; void destory()struct pcb *pr;freenc();pr=tou;if(pr-link!=null) tou=tou-link; free(pr); all-; if(tou-itimetim) sort(); else free(pr); all=0;void running()struct
31、 pcb *pr;pr=tou;pr-rtime=pr-rtime+1;pr-state=r;tim+;check();if(pr-rtime=pr-ntime) destory();else pr-state=w;sort();innc();void main()char ch;clrscr();creatnc();creatpcb();check();while(all0)running();ch=getchar();printf(the process are finishedn);(4) 每個函數(shù)的流程圖:首次適應(yīng)算法(ff):開始(1)innc() 函數(shù):該函數(shù)用于將進程裝入內(nèi)存。s
32、truct nc *md;struct pcb *xx;xx=tou;xx是否為空 否 是xx-ncn=0&(xx-itimeitimerl大于等于xx-nv是否xx-ncn=md-n;xx-sdzv=md-sdz;md-sdz=md-sdz+xx-nvmd-rl=md-rl-xx-nv;goto leep;md=md-nextxx=xx-link開始(2)sort() 函數(shù):struct pcb *p1,*p2;p1=p2=tou;p1-link是否為空?是(p1-link)-itime小于等于tim而且(p1-link)-ncn不為零否結(jié)束否p1=p1-link是tou=p2=p1p1-l
33、ink是否為空?否是p1-link=toutou=tou-linkp2-link=nullp1=p1-link(3)creatnc()函數(shù):該函數(shù)用于創(chuàng)建內(nèi)存鏈表。 開始 輸入內(nèi)存號ncx大于0?是否 p1-n=ncx 輸入內(nèi)存大小輸入內(nèi)存的首地址 p1-sdz=ncy p2-next=p1 p2=p1 輸入內(nèi)存號 結(jié)束ncx小于等于0?否breakp1=(struct nc*)malloc(sizeof(struct nc)p1-next=null(4)creatpcb()函數(shù):該函數(shù)用于創(chuàng)建進程鏈表。 開始輸入要創(chuàng)建的pcb個數(shù)i小于all? 是否調(diào)用函數(shù)innc()p1=(struct
34、pcb*)malloc(sizeof(struct pcb)p1-link=null若(i=0) 則tou=p2=p1輸入第x個pcb的名輸入這個pcb的大小輸入這個pcb進入內(nèi)存的時間輸入這個pcb運行的時間p1-state=wp1-rtime=0p1-ncn=0若i不為零則p2-link=p1;p2=p1tou-itime大于tim? 是調(diào)用函數(shù)sort() 結(jié)束(5)disp(pcb * pr) 函數(shù):該函數(shù)用于建立進程顯示函數(shù),顯示當前進程。 開始分別輸出進程名、進程狀態(tài)、裝入的內(nèi)存號、進程運行總時間和進程運行時間 結(jié)束(6)check()函數(shù):該函數(shù)用于查看進程。 開始顯示當前運行進
35、程顯示就緒隊列狀態(tài)pr是否為空? 否是 結(jié)束pr-itime小于等于tim?是否調(diào)用disp(pr)pr=pr-link 開始(7)look()函數(shù):pr=headpr是否為空?否是輸出進程號、內(nèi)存容量和首地址 結(jié)束 pr=pr-next(8)freenc()函數(shù):該函數(shù)用于內(nèi)存釋放。 開始struct nc *dncstruct pcb *pr,*pldnc=headpr=pl=toudnc是否為空? 否是pr-sdzv+pr-nv等于dnc-n?dnc-n等于pr-ncn?是否 否dnc=dnc-nextbreakdnc-n=pr-sdzvdnc-rl=dnc-rl+pr-nvpl是否為空
36、?是 否pl-ncn等于dnc-n?dnc-sdz=dnc-sdz-pr-nvdnc-rl=pr-nv 是否pr-sdzv+pr-nv小于pl-sdzv?否是 結(jié)束pl-sdzv=pl-sdzv-pr-nvpl=pl-link(9)destory()函數(shù): 開始調(diào)用freenc()pr-link是否為空?否是tou=tou-linkfree(pr)all-free(pr)all=0tou-itime大于tim? 是 否調(diào)用sort() 結(jié)束 開始(10)running()函數(shù):struct pcb *prpr=toupr-rtime=pr-rtime+1pr-state=rtim+調(diào)用chec
37、k()調(diào)用look()pr-rtime大于等于pr-ntime?是否pr-state=w調(diào)用destory()調(diào)用innc()調(diào)用sort() 結(jié)束(11)主函數(shù): 開始 清屏調(diào)用creatnc()調(diào)用creatpcb()調(diào)用check()all大于零?是否調(diào)用running()調(diào)用getch()進程已完成 結(jié)束循環(huán)首次適應(yīng)算法(nf):(1)innc()函數(shù):該函數(shù)用于將進程裝入內(nèi)存。 開始struct pcb *xx; xx=tou;xx是否為空 否 是xx-itime小于等于tim?結(jié)束 是否head是否為空? 是head是否為空head-rl大于xx-nv?是否是pcb不能進入內(nèi)存因為
38、內(nèi)存沒容量了head-rl=head-rl-xx-nvxx-sdzv=head-sdzhead-sdz=head-sdz+xx-nvxx-ncn=head-nbreakxx=xx-linkhead=head-next(2)sort()函數(shù): 開始struct pcb *p1,*p2;p1=p2=tou;p1是否為空?是(p1-link)-itime小于等于tim?否結(jié)束否p1=p1-link是tou=p2=p1p1-link是否為空?否是p1-link=toutou=tou-linkp2-link=nullp1=p1-link(3)creatnc()函數(shù):該函數(shù)用于創(chuàng)建內(nèi)存鏈表。 開始 輸入內(nèi)
39、存號ncx大于0?是否 p1-n=ncx 輸入內(nèi)存大小輸入內(nèi)存的首地址 p1-sdz=ncy p2-next=p1 p2=p1 輸入內(nèi)存號p2-next=head 結(jié)束p1=(struct nc*)malloc(sizeof(struct nc)(4)creatpcb()函數(shù):該函數(shù)用于創(chuàng)建進程鏈表。 開始輸入要創(chuàng)建的pcb個數(shù)i小于all? 是否p1=(struct pcb*)malloc(sizeof(struct pcb)p1-link=null若(i=0) 則tou=p2=p1輸入第x個pcb的名輸入這個pcb的大小輸入這個pcb進入內(nèi)存的時間輸入這個pcb運行的時間p1-state=wp1-rtime=0p2-link=p1p2=p1調(diào)用函數(shù)innc()
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 唐山市2024-2025學(xué)年高一上學(xué)期期末考試英語試卷(含答案)
- 中國詩詞大會:30道關(guān)于詩詞中兒童形象的選擇題(附答案和解釋)
- 2025年區(qū)塊鏈技術(shù)考試題及答案
- 2025年大咯血考試試題及答案
- 2025年暴雨心理測試試題及答案
- 保健按摩師中級復(fù)習測試附答案
- 工業(yè)機器人應(yīng)用編程1+X中級練習試題
- 工業(yè)機器人復(fù)習試題含答案
- 2025年二波疫情測試題及答案
- 2025年傳熱學(xué)試題庫及答案
- 應(yīng)用文寫作-2020-2024年高考英語試題分類匯編(解析版)
- 離心式泵安裝
- 橋式起重機PLC控制改造設(shè)計
- 《老舍及作品分析》課件
- 高考語文復(fù)習【知識精研】信息類文本閱讀 課件
- 2024年9月證券專項《證券投資顧問業(yè)務(wù)》真題卷(74題)
- 保健品項目的商業(yè)計劃書五篇
- 印章管理責任承諾書4篇
- 《吊裝起重作業(yè)培訓(xùn)》課件
- 2024年度供應(yīng)商管理培訓(xùn)課件
- 6、水平四+田徑18課時大單元計劃-《雙手頭上前擲實心球》
評論
0/150
提交評論