南昌大学计算机操作系统实验报告

上传人:飞*** 文档编号:35542736 上传时间:2018-03-17 格式:DOC 页数:32 大小:1.02MB
返回 下载 相关 举报
南昌大学计算机操作系统实验报告_第1页
第1页 / 共32页
南昌大学计算机操作系统实验报告_第2页
第2页 / 共32页
南昌大学计算机操作系统实验报告_第3页
第3页 / 共32页
南昌大学计算机操作系统实验报告_第4页
第4页 / 共32页
南昌大学计算机操作系统实验报告_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《南昌大学计算机操作系统实验报告》由会员分享,可在线阅读,更多相关《南昌大学计算机操作系统实验报告(32页珍藏版)》请在金锄头文库上搜索。

1、实 验 报 告实验课程: 计算机操作系统 学生姓名: 学 号: 专业班级: 2012 年 12 月 19 日目 录实验一 编程实现银行家安全算法实验二 进程调度算法的实现实验三 存储管理的模拟实现一、实验目的通过实验加强对银行家安全算法的理解和掌握。二、实验内容熟悉避免死锁发生的方法,死锁与安全序列的关系,编程实现银行家算法,要求输出进程的安全序列。三、实验要求1、需写出设计说明;2、设计实现代码及说明3、运行结果;四、主要实验步骤设计说明:假定系统中有五个进程P0,P1,P2,P3,P4和三类资源的数量分别为10、5、7,在 T0时刻的资源分配情况如下图示:资源情况进程MaxA B CAll

2、ocationA B CNeedA B CAvailableA B CP07 5 30 1 07 4 3 3 3 2P1 3 2 2 2 0 01 2 2P29 0 2 3 0 2 6 0 0P3 2 2 2 2 1 1 0 1 1P4 4 3 3 0 0 2 4 3 1假设在此后任一时刻有一个进程 P 发出请求向量 request,通过发出的向量判断是否可以满足需要,如果可以,则假设将该资源予以分配,并通过安全性算法进行检测,如果安全,则找出安全序列,否则系统不安全,将分配的资源回收。代码设计:将 5 个进程的所有信息放在一个对应的结构体 struct pro【i】中,系统资源数和进程请求资

3、源分别存放在 available 和 request 数组中,同时通过建立一个finishi 布尔数组来控制和标识 5 个进程的完成情况,如果最后 finish 值都为真,则说明分配资源后系统是安全的,否则,不安全并将资源回收。银行家算法实现代码:#include #include int main(void) struct process int max3;int allocation3;int need3; pro5=7,5,3,0,1,0,7,4,3,3,2,2,2,0,0,1,2,2, 9,0,2,3,0,2,6,0,0,2,2,2,2,1,1,0,1,1, 4,3,3,0,0,2,4

4、,3,1; int available3=3,3,2,request3; int work3,finish5=0; int m,i,j,k,count=0,number=0; int r=0,rank5=0; printf(“t2*银行家算法*2n“);printf(“The information of processes and system:n“); printf(“tnamet maxtallocationt needtavailablen“); for(i=0;i int main(void) struct process char pro_name10; float arrivet

5、ime; float servetime; floatstarttime; floatfinishtime; floatcircle_time; floatd_circle_time; a100;/用结构体存放各进程的相关信息int i,j,k,N; process temp; printf(“请输入进程数:“);scanf(“%d“,/进程数 printf(“请输入进程信息(包括进程名、进程到达时间、进程服务时间): n“);for(i=0;i int main(void) struct process char pro_name10; float arrivetime; float ser

6、vetime; floatstarttime; floatfinishtime; floatcircle_time; floatd_circle_time; a100; int i,j,k=0,N; process temp; process t; printf(“请输入进程数:“);scanf(“%d“, printf(“请输入进程信息(包括进程名、进程到达时间、进程服务时间:n “);for(i=0;i int main(void) struct process char name10; float arrivetime; float servetime; floatstarttime;

7、floatfinishtime; floatcycle_time; floatd_cycle_time; pro100; int i,j,N,t,k,l=1; int count=1; float add,min_arrive,priority,max=0; process temp; printf(“请输入进程数:“);scanf(“%d“, printf(“请输入进程信息(包括进程名、进程到达时间、进程服务时间)n“);for(i=0;imax) max=priority; k=i; count+; add=add+prok.servetime; temp=prok; prok=prol;

8、 prol=temp; prol.starttime=add; l=l+1; printf(“n 进程调度顺序为:n“);for(i=0;i int main(void) struct process char name10; float arrivetime; float servetime; float starttime; float finishtime; float cycletime; float d_cycletime; pro100; float size; int i,j,N,count=0; float resttime100,time; printf(“t*时间片轮转调度

9、算法*nn“); printf(“please input the process number:“); scanf(“%d“, printf(“please input the processes information(name and servetime):n“); for(i=0;i #include #include int main(void) int order320,mem_volume4=100,100,100,100; int l=0,i=0,j,num=0,cx,sign=0,add=0; float value=0,sum=0; srand(time(NULL); fo

10、r(cx=0;cx #include #include int main(void) int order320,mem_volume4=100,100,100,100; int l=0,i=0,j,cx; int num,temp=0,ex_chan=0,add=0; float value=0,sum=0; srand(time(NULL); for(cx=0;cx0;j-) temp=mem_volumej; mem_volumej=mem_volumej-1; mem_volumej-1=temp; else if(orderi+1)/10=mem_volume3) for(j=3;j0

11、;j-) temp=mem_volumej; mem_volumej=mem_volumej-1; mem_volumej-1=temp; /如果所调页数同第 3、4 个内存块中页数相同,则通过循环进行排序else l+; if(mem_volume3=100) mem_volume3=(orderi+1)/10;/保证刚开始调入内存块中就产生缺页else mem_volume3=(orderi+1)/10; for(num=3;num0;num-) ex_chan=mem_volumenum; mem_volumenum=mem_volumenum-1; mem_volumenum-1=ex

12、_chan;/写人后重新排序 i+; orderi=rand()%(orderi-1+2); if(orderi/10=mem_volume0) ; else if(orderi/10=mem_volume1) temp=mem_volume1; mem_volume1=mem_volume0; mem_volume0=temp; else if(orderi/10=mem_volume2) for(j=2;j0;j-) temp=mem_volumej; mem_volumej=mem_volumej-1; mem_volumej-1=temp; else if(orderi/10 = me

13、m_volume3) for(j=3;j0;j-) temp=mem_volumej; mem_volumej=mem_volumej-1; mem_volumej-1=temp; else l+; if(mem_volume2=100) mem_volume2=orderi/10; else mem_volume3=orderi/10; for(num=3;num0;num-) ex_chan=mem_volumenum; mem_volumenum=mem_volumenum-1; mem_volumenum-1=ex_chan; i+; orderi=orderi-1+1; if(ord

14、eri/10= mem_volume0) ; else if(orderi/10 = mem_volume1) temp=mem_volume1;mem_volume1=mem_volume0; mem_volume0=temp; else if(orderi/10 = mem_volume2) for(j=2;j0;j-) temp=mem_volumej; mem_volumej=mem_volumej-1; mem_volumej-1=temp; else if(orderi/10=mem_volume3) for(j=3;j0;j-) temp=mem_volumej; mem_volumej=mem_volumej-1; mem_volumej-1=temp; else l+; if(mem_volume1=100) mem_volume1=orderi/10; else mem_volume3=orderi/10; for(num=3;num0;num-) ex_chan=mem_volumenum; mem_volumenu

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 企业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号