操作系统实验(3)存储管理实验

上传人:1666****666 文档编号:36245936 上传时间:2021-10-30 格式:DOC 页数:38 大小:542KB
收藏 版权申诉 举报 下载
操作系统实验(3)存储管理实验_第1页
第1页 / 共38页
操作系统实验(3)存储管理实验_第2页
第2页 / 共38页
操作系统实验(3)存储管理实验_第3页
第3页 / 共38页
资源描述:

《操作系统实验(3)存储管理实验》由会员分享,可在线阅读,更多相关《操作系统实验(3)存储管理实验(38页珍藏版)》请在装配图网上搜索。

1、 操作系统实验(3) 实验题目:存 储 管 理 实 验课程名称:操 作 系 统 学 院:管 理 学 院 专业班级: 学 号(1): 姓 名(1): 学 号(2): 姓 名(2): 任课教师: 2010年05月06日学院:管 理 学 院 班级: 组员: 组员: 评定: 实验题目:存储管理实验(1) 实验目的:通过编写和调试存储管理的模拟程序以加深对存储管理方案的 理解。(2)实验内容:设计一个可变式分区分配的存储管理方案。并模拟实现分区的 分配和回收过程。 对分区的管理法可以是下面三种算法之一: 首次适应算法 循环首次适应算法 最佳适应算法(3) 源代码(含注释):首次适应算法(FF):#inc

2、lude#include#include#includestruct nc int n; /*内存号*/ int rl; /*内存容量*/ int sdz; /*首地址*/ struct nc *next;*head;struct PCB int num; /*进程号*/ char name10; /*进程名*/ int nv; /*进程大小*/ int itime; /*进程进入内存时间*/ int ncn; /*装入的内存号*/ int sdzv; /*存入内存的首地址*/ int ntime; /*进程运行总时间*/ int rtime; /*进程运行时间*/ char state; /

3、*进程状态*/ struct PCB *link;*tou;int all; /*进程总数变量*/int tim=0; /*当前时间变量*/void innc() /*将进程装入内存*/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() /*创建内存链表*/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() /*创建进程链表*/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) /*建立进程显示函数,用于显示当前进程*/ 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() /* 建立进程查看函数 */ 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); /*显示就绪队列状态*/ 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() /*内存释放*/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);循环首次适应算法(NF):#include#include#include#includestruct nc int n; /*内存号*/ int rl; /*内存容量*/ int sdz; /*首地址*/ struct nc *next;*head;struct PCB int num; /*进程号*/ char name10; /*进程名*/ int nv;

13、 /*进程大小*/ int itime; /*进程进入内存时间*/ int ncn; /*装入的内存号*/ int sdzv; /*存入内存的首地址*/ int ntime; /*进程运行总时间*/ int rtime; /*进程运行时间*/ char state; /*进程状态*/ struct PCB *link;*tou;int all; /*进程总数变量*/int tim=0; /*当前时间变量*/void innc() /*将进程装入内存*/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() /*创建内存链表*/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() /*创建进程链表*/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) /*建立进程显示函数,用于显示当前进程*/ 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() /* 建立进程查看函数 */ 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() /*内存释放*/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);最佳适应算法(BF):#include#include#include#includestruct nc in

22、t n; /*内存号*/ int rl; /*内存容量*/ int sdz; /*首地址*/ struct nc *next;*head;struct PCB int num; /*进程号*/ char name10; /*进程名*/ int nv; /*进程大小*/ int itime; /*进程进入内存时间*/ int ncn; /*装入的内存号*/ int sdzv; /*存入内存的首地址*/ int ntime; /*进程运行总时间*/ int rtime; /*进程运行时间*/ char state; /*进程状态*/ struct PCB *link;*tou;int all; /

23、*进程总数变量*/int tim=0; /*当前时间变量*/void innc() /*将进程装入内存*/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() /*创建内存链表*/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() /*创建进程链表*/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) /*建立进程显示函数,用于显示当前进程*/ 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() /* 建立进程查看函数 */ 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() /*内存释放*/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) 每个函数的流程图:首次适应算法(FF):开始(1)innc() 函数:该函数用于将进程装入内存。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() 函数:struct PCB *p1,*p2;p1=p2=tou;p1-link是否为空?是(p1-link)-itime小于等于tim而且(p1-link)-ncn不为零否结束否p1=p1-link是tou=p2=p1p1-l

33、ink是否为空?否是p1-link=toutou=tou-linkp2-link=NULLp1=p1-link(3)creatnc()函数:该函数用于创建内存链表。 开始 输入内存号ncx大于0?是否 p1-n=ncx 输入内存大小输入内存的首地址 p1-sdz=ncy p2-next=p1 p2=p1 输入内存号 结束ncx小于等于0?否breakp1=(struct nc*)malloc(sizeof(struct nc)p1-next=NULL(4)creatPCB()函数:该函数用于创建进程链表。 开始输入要创建的PCB个数i小于all? 是否调用函数innc()p1=(struct

34、PCB*)malloc(sizeof(struct PCB)p1-link=NULL若(i=0) 则tou=p2=p1输入第X个PCB的名输入这个PCB的大小输入这个PCB进入内存的时间输入这个PCB运行的时间p1-state=wp1-rtime=0p1-ncn=0若i不为零则p2-link=p1;p2=p1tou-itime大于tim? 是调用函数sort() 结束(5)disp(PCB * pr) 函数:该函数用于建立进程显示函数,显示当前进程。 开始分别输出进程名、进程状态、装入的内存号、进程运行总时间和进程运行时间 结束(6)check()函数:该函数用于查看进程。 开始显示当前运行进

35、程显示就绪队列状态pr是否为空? 否是 结束pr-itime小于等于tim?是否调用disp(pr)pr=pr-link 开始(7)look()函数:pr=headpr是否为空?否是输出进程号、内存容量和首地址 结束 pr=pr-next(8)freenc()函数:该函数用于内存释放。 开始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?否是 结束pl-sdzv=pl-sdzv-pr-nvpl=pl-link(9)destory()函数: 开始调用freenc()pr-link是否为空?否是tou=tou-linkfree(pr)all-free(pr)all=0tou-itime大于tim? 是 否调用Sort() 结束 开始(10)running()函数:struct PCB *prpr=toupr-rtime=pr-rtime+1pr-state=rtim+调用chec

37、k()调用look()pr-rtime大于等于pr-ntime?是否pr-state=w调用destory()调用innc()调用sort() 结束(11)主函数: 开始 清屏调用creatnc()调用creatPCB()调用check()all大于零?是否调用running()调用getch()进程已完成 结束循环首次适应算法(NF):(1)innc()函数:该函数用于将进程装入内存。 开始struct PCB *xx; xx=tou;xx是否为空 否 是xx-itime小于等于tim?结束 是否head是否为空? 是head是否为空head-rl大于xx-nv?是否是PCB不能进入内存因为

38、内存没容量了head-rl=head-rl-xx-nvxx-sdzv=head-sdzhead-sdz=head-sdz+xx-nvxx-ncn=head-nbreakxx=xx-linkhead=head-next(2)sort()函数: 开始struct PCB *p1,*p2;p1=p2=tou;p1是否为空?是(p1-link)-itime小于等于tim?否结束否p1=p1-link是tou=p2=p1p1-link是否为空?否是p1-link=toutou=tou-linkp2-link=NULLp1=p1-link(3)creatnc()函数:该函数用于创建内存链表。 开始 输入内

39、存号ncx大于0?是否 p1-n=ncx 输入内存大小输入内存的首地址 p1-sdz=ncy p2-next=p1 p2=p1 输入内存号p2-next=head 结束p1=(struct nc*)malloc(sizeof(struct nc)(4)creatPCB()函数:该函数用于创建进程链表。 开始输入要创建的PCB个数i小于all? 是否p1=(struct PCB*)malloc(sizeof(struct PCB)p1-link=NULL若(i=0) 则tou=p2=p1输入第X个PCB的名输入这个PCB的大小输入这个PCB进入内存的时间输入这个PCB运行的时间p1-state=

40、wp1-rtime=0p2-link=p1p2=p1调用函数innc() tou-itime大于tim?调用函数sort()是 结束(5)disp(PCB * pr)函数:建立进程显示函数,用于显示当前进程。 开始分别输出进程名、进程状态、装入的内存号、进程运行总时间和进程运行时间 结束(6)check()函数:建立进程查看函数。 开始显示当前运行进程显示就绪队列状态pr是否为空? 否是 结束pr-itime小于等于tim?是否调用disp(pr)pr=pr-link(7)freenc()函数:该函数用于内存释放。 开始struct nc *dncstruct PCB *pr,*pldnc=h

41、eadpr=pl=toudnc是否为空? 否是pr-sdzv+pr-nv等于dnc-n?dnc-n等于pr-ncn?是否否dnc-n=pr-sdzvdnc-rl=dnc-rl+pr-nvdnc=dnc-nextbreak pl是否为空?否是pl-ncn等于dnc-n?dnc-sdz=dnc-sdz-pr-nvdnc-rl=pr-nv否是 结束pr-sdzv+pr-nv小于pl-sdzv?是否 结束pl-sdzv=pl-sdzv-pr-nvpl=pl-link(8)destory()函数: 开始调用freenc()pr-link是否为空?否是tou=tou-linkfree(pr)all-fre

42、e(pr)all=0tou-itime大于tim? 是否调用Sort() 结束(9)running()函数: 开始struct PCB *prpr=toupr-rtime=pr-rtime+1pr-state=rtim+调用check()pr-rtime大于等于pr-ntime?是否pr-state=w调用destory()调用innc()调用sort() 结束(10)主函数: 开始 清屏调用creatnc()调用creatPCB()调用check()all大于零?是否调用running()ch=getchar()进程已完成 结束最佳适应算法(BF):(1) innc()函数:该函数用于将进程

43、装入内存。 开始struct nc *mdstruct PCB *xx;xx=tou; md=headxx是否为空 否 是xx-itime小于等于tim?结束 是否md是否为空? 是md是否为空md-rl大于xx-nv?是否是PCB不能进入内存因为内存没容量了md-rl=md-rl-xx-nvxx-sdzv=md-sdzmd-sdz=md-sdz+xx-nvxx-ncn=md-nbreakmd=md-nextxx=xx-link(2) sort()函数: 开始struct PCB *p1,*p2;p1=p2=tou;p1是否为空?是(p1-link)-itime小于等于tim?否结束否p1=p1-link是tou=p2=p1p1-link是否为空?否是p1-link=toutou=tou-linkp2-link=NULLp1=p1-link 开始(3) ncsort()函数:struct nc *p1,*p2,*p3int i=0,jp1=headp1是否为空?否是结束

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!