版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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=wp1-rtime=0p2-link=p1p2=p1调用函数innc()
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 配电工程招投标环境评估
- 终止总承包合同相关法律
- 大庆市房屋销售协议
- 法律约束不侵权保证书
- 学校保证书中的安全管理制度
- 迟到的原因及反思
- 政府采购合同性质的争议与探讨
- 艺人经济合约范本
- 标准工程分包合同版
- 招标文件的模板化处理技术
- 广东省中小学幼儿园教师违反职业道德行为处理工作指引
- 强制隔离戒毒所安防信息化建设项目可行性研究报告
- “唯物史观”素养在初中历史教学中的渗透-以《列宁与十月革命》一课为例
- 八年级英语 The fisherman and the fish 教学设计
- 物流园产业园项目经济测算报告
- 小班幼儿卫生习惯的评价
- 沈阳好好宠物医院有限公司建设项目环境影响报告
- RFJ05-2009-DQ人民防空工程电气大样图集
- 以丑而伤以强凌弱-《猫》
- 火电厂脱硫系统及脱硝技术介绍演示文稿
- 安全讲师演讲环节评分标准
评论
0/150
提交评论