OS实验指导书(蒋剑修改) - 图文(9)

2020-02-20 14:01

s=(float)319*rand( )/32767/32767/2+1; /*正态分布*/ for(i=0;i319) { printf(\ exit(0); } a[i]=s; /*任选一指令访问点m*/ a[i+1]=a[i]+1; /*顺序执行一条指令*/ a[i+2]=(float)a[i]*rand( )/32767/32767/2; /*执行前地址指令m*/ a[i+3]=a[i+2]+1; /*顺序执行一条指令*/ s=(float)(318-a[i+2])*rand( )/32767/32767/2+a[i+2]+2; if((a[i+2]>318)||(s>319)) printf(\ } for (i=0;i

/*初始化相关数据结构 total_pf表示内存的块数 */

int initialize(int total_pf) { int i; diseffect=0;

39

for(i=0;i

int FIFO(int total_pf) /*先进先出算法total_pf:用户进程的内存页面数*/ { int i,j; pfc_type *p; /*中间变量*/ initialize(total_pf); /*初始化相关页面控制用数据结构*/ busypf_head=busypf_tail=NULL; /*忙页面队列头,队列尾链接*/ for(i=0;inext; pl[busypf_head->pn].pfn=INVALID; freepf_head=busypf_head; /*释放忙页面队列的第一个页面*/ freepf_head->next=NULL; /*表明还是缺页*/ busypf_head=p; } p=freepf_head->next; freepf_head->pn=page[i]; pl[page[i]].pfn=freepf_head->pfn; freepf_head->next=NULL; /*使busy的尾为null*/ if(busypf_tail==NULL) {

40

busypf_tail=busypf_head=freepf_head; } else { busypf_tail->next=freepf_head; busypf_tail=freepf_head; } freepf_head=p; } } printf(\ return 0;

int LRU (int total_pf) /*最近最久未使用算法least recently used*/ { int min,minj,i,j,present_time; /*minj为最小值下标*/ initialize(total_pf); present_time=0; for(i=0;ipl[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=0; freepf_head->next=NULL; } pl[page[i]].pfn=freepf_head->pfn; //有空闲页面,改为有效 pl[page[i]].time=present_time; freepf_head=freepf_head->next; //减少一个free 页面 } else

41

{ pl[page[i]].time=present_time; //命中则增加该单元的访问次数 present_time++; } } printf(\ return 0; }

int NUR(int total_pf ) /*最近未使用算法Not Used recently count表示*/ {

int i,j,dp,cont_flag,old_dp; pfc_type *t;

initialize(total_pf); dp=0;

for(i=0;inext=NULL; }

42

pl[page[i]].pfn=freepf_head->pfn; freepf_head->pn=page[i]; freepf_head=freepf_head->next; } else pl[page[i]].counter=1; if(i%clear_period==0) for(j=0;j

printf(\return 0; }

int OPT(int total_pf) /*最佳置换算法*/ { int i,j, max,maxpage,d,dist[total_vp]; pfc_type *t; initialize(total_pf); for(i=0;i

43


OS实验指导书(蒋剑修改) - 图文(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:CRISPR系统

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: