操作系统课设程序源_操作系统课设
操作系统课设程序源由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“操作系统课设”。
南京工程学院
课程设计报告
课 程 名 称 操作系统原理与应用 实 验 名 称 储存管理 院(系、部、中心)
通信工程学院
专
业
通信工程
班 级 信息工程111 姓 名 车含喆 学 号 208110808 起 止 日 期 2014.4.22 指 导 教 师 耿鹏
1、实验目的1.通过模拟实现请求页式存储管理的几种基本页面置换算法。2.了解虚拟存储技术的特点
3.掌握虚拟存储请求页式存储管理中几种基本页面置换算法的基本思想和实现过程,并比较它们的效率。
2、实验内容
3、实验设备
PC 1台,Ubuntu 操作系统
4、实验总结
UNIX中,为了提高内存利用率,提供了内外存进程对换机制;内存空间的分配和回收均以页为单位进行;一个进程只需将其一部分调入内存便可运行;还支持请求调页的储存管理方式。
5.实验程序
#include #include #include #define TRUE 1 #define FALSE 0 #define INVALID-1 #define NULL 0 #define total_instruction 320 #define total_vp 32 #define clear_period 50 typedef struct { int pn,pfn,counter,time;}pl_type;pl_type pl[total_vp];struct pfc_struct{
};typedef struct pfc_struct pfc_type;pfc_type pfc[total_vp],*freepf_head,*busypf_head,*busypf_tail;int diseffect, a[total_instruction];int page[total_instruction],offset[total_instruction];int initialize(int);int FIF0(int);int LRU(int);int LFU(int);int NUR(int);int OPT(int);int pn,pfn;struct pfc_struct *next;
int main(){ int s,j,i;srand(10*getpid());s=(float)319*rand()/32767/32767/2+1;
for(i=0;i318)||(s>319))printf(“a[%d+2],a number which is :%d and == %dn”,i,a[i+2],s);for(i=0;i
} int initialize(total_pf)int total_pf;{ int i;diseffect=0;for(i=0;i
{
} for(i=0;i
} return 0;LRU(i);OPT(i);
} pfc[i].next=&pfc[i+1];pfc[i].pfn=i;pfc[total_pf-1].next=NULL;
} int FIFO(total_pf)int total_pf;{
int i,j;pfc_type *p;initialize(total_pf);busypf_head=busypf_tail=NULL;for(i=0;i
} printf(“FIFO:%6.4fn”,1-(float)diseffect/320);return 0;if(pl[page[i]].pfn==INVALID){ diseffect+=1;if(freepf_head==NULL){ p=busypf_head==NULL;pl[busypf_head->pn].pfn=INVALID;freepf_head=busypf_head;freepf_head->next=NULL;busypf_head=p;} p=freepf_head->next;freepf_head->next=NULL;freepf_head->pn=page[i];pl[page[i]].pfn=freepf_head->pfn;if(busypf_tail==NULL)busypf_head=busypf_tail=freepf_head;else {
} freepf_head=p;} busypf_tail->next=freepf_head;busypf_tail=freepf_head;pfc[total_pf-1].pfn=total_pf-1;freepf_head=&pfc[0];return 0;
} int LRU(total_pf)int total_pf;{
int min,minj,i,j,present_time;initialize(total_pf);present_time=0;for(i=0;i
} if(pl[page[i]].pfn==INVALID){
} else pl[page[i]].time=present_time;diseffect++;if(freepf_head=NULL){
} pl[page[i]].pfn=freepf_head->pfn;pl[page[i]].time=present_time;freepf_head=freepf_head->next;min=32767;for(j=0;j
if(min>pl[j].time&&pl[j].pfn!=INVALID){
}
min=pl[j].time;minj=j;freepf_head=&pfc[pl[minj].pfn];pl[minj].pfn=INVALID;pl[minj].time=-1;freepf_head->next=NULL;present_time++;printf(“LRU:%6.4fn”,1-(float)diseffect/320);} int OPT(total_pf)int total_pf;{ int i,j,max,maxpage,d,dist[total_vp];
pfc_type *t;initialize(total_pf);for(i=0;i
}
freepf_head->next=NULL;pl[maxpage].pfn=INVALID;}
diseffect++;if(freepf_head==NULL){
for(j=0;jpfn;freepf_head=freepf_head->next;} } printf(“OPT:%6.4fn”,1-(float)diseffect/320);return 0;