1、先来先服务算法和银行家算法江西师范大学计算机信息工程学院学生实验报告(一)专业_计算机科学与技术(师范) 姓名_ 李洋 学号 _0908061086 日期_ 2011-4-6 课程名称计算机操作系统实验室名称X4313实验名称FCFS的调度算法实现指导教师朱明华成绩1.实验目的:熟悉进程调度算法,用C语言实现先来先服务调度算法2.实验原理和内容:求进程的处理时间和平均处理时间3.实验步骤使用C-Free编译器,编制程序,调试程序4.程序及运行结果#include typedef struct link int time; int p; struct link *next; node; node
2、 *creat() int m,n; node *head,*q,*s; head=q=(node *)malloc(sizeof(node); printf(please input time and priority:); scanf(%d%d,&m,&n); while(m&n) s=(node *)malloc(sizeof(node); s-p=n; s-time=m; q-next=s; q=s; scanf(%d%d,&m,&n); q-next=NULL; return head; int main() int sum=0,k=0,t=0; node *head,*l; hea
3、d=creat(); l=head-next; while(l) sum+=l-time; l-time=sum; l=l-next; k+=sum; l=head-next; printf(each time is:) printf(n); printf(the averagetime is %d,k/t); return 0;while(l) printf(%4d,l-time); l=l-next; t+; printf(n); printf(the averagetime is %d,k/t); return 0;运行结果:江西师范大学计算机信息工程学院学生实验报告(二)专业_计算机科
4、学与技术(师范) 姓名_ 李洋 学号 0908061086_ 日期_ 2011-4-6 课程名称计算机操作系统实验室名称X4313实验名称银行家算法指导教师朱明华成绩1. 实验目的:模拟实现银行家算法,用银行家算法实现资源分配。2.实验原理和内容:设计五个进程P0,P1,P2,P3,P4共享三类资源A,B,C的系统,A,B,C的资源数量分别为10,5,7。进程可动态地申请资源和释放资源,系统按各进程的申请动态地分配资源。要求程序具有显示和打印各进程的某一时刻的资源分配表和安全序列;显示和打印各进程依次要求申请的资源号以及为某进程分配资源后的有关资源数据。3.实验步骤使用C-Free编译器,编制
5、程序,调试程序4.源程序:#include malloc.h #include stdio.h #include stdlib.h #define alloclen sizeof(struct allocation) #define maxlen sizeof(struct max) #define avalen sizeof(struct available) #define needlen sizeof(struct need) #define finilen sizeof(struct finish) #define pathlen sizeof(struct path) struct
6、allocation int value; struct allocation *next; ; struct max int value; struct max *next; ; struct available /*可用资源数*/ int value; struct available *next; ; struct need /*需求资源数*/ int value; struct need *next; ; struct path int value; struct path *next; ; struct finish int stat; struct finish *next; ;
7、int main() int row,colum,status=0,i,j,t,temp,processtest; struct allocation *allochead,*alloc1,*alloc2,*alloctemp; struct max *maxhead,*maxium1,*maxium2,*maxtemp; struct available *avahead,*available1,*available2,*workhead,*work1,*work2,*worktemp,*worktemp1; struct need *needhead,*need1,*need2,*need
8、temp; struct finish *finihead,*finish1,*finish2,*finishtemp; struct path *pathhead,*path1,*path2; printf(n请输入系统资源的种类数:); scanf(%d,&colum); printf(请输入现时内存中的进程数:); scanf(%d,&row); printf(请输入已分配资源矩阵:n); for(i=0;irow;i+) for (j=0;jnext=alloc2-next=NULL; scanf(%d,&allochead-value); status+; else alloc2=(
9、struct allocation *)malloc(alloclen); scanf(%d,%d,&alloc2-value); if(status=1) allochead-next=alloc2; status+; alloc1-next=alloc2; alloc1=alloc2; alloc2-next=NULL; status=0; printf(请输入最大需求矩阵:n); for(i=0;irow;i+) for (j=0;jnext=maxium2-next=NULL; scanf(%d,&maxium1-value); status+; else maxium2=(struc
10、t max *)malloc(maxlen); scanf(%d,%d,&maxium2-value); if(status=1) maxhead-next=maxium2; status+; maxium1-next=maxium2; maxium1=maxium2; maxium2-next=NULL; status=0; printf(请输入现时系统剩余的资源矩阵:n); for (j=0;jnext=available2-next=NULL; work1-next=work2-next=NULL; scanf(%d,&available1-value); work1-value=ava
11、ilable1-value; status+; else available2=(struct available*)malloc(avalen); work2=(struct available*)malloc(avalen); scanf(%d,%d,&available2-value); work2-value=available2-value; if(status=1) avahead-next=available2; workhead-next=work2; status+; available1-next=available2; available1=available2; wor
12、k1-next=work2; work1=work2; available2-next=NULL; work2-next=NULL; status=0; alloctemp=allochead; maxtemp=maxhead; for(i=0;irow;i+) for (j=0;jnext=need2-next=NULL; need1-value=maxtemp-value-alloctemp-value; status+; else need2=(struct need *)malloc(needlen); need2-value=(maxtemp-value)-(alloctemp-va
13、lue); if(status=1) needhead-next=need2; status+; need1-next=need2; need1=need2; maxtemp=maxtemp-next; alloctemp=alloctemp-next; need2-next=NULL; status=0; for(i=0;inext=finish2-next=NULL; finish1-stat=0; status+; else finish2=(struct finish*)malloc(finilen); finish2-stat=0; if(status=1) finihead-nex
14、t=finish2; status+; finish1-next=finish2; finish1=finish2; finish2-next=NULL; /*Initialization compleated*/ status=0; processtest=0; for(temp=0;temprow;temp+) alloctemp=allochead; needtemp=needhead; finishtemp=finihead; worktemp=workhead; for(i=0;istat=0) for(j=0;jnext,worktemp=worktemp-next) if(nee
15、dtemp-valuevalue) processtest+; if(processtest=colum) for(j=0;jvalue+=alloctemp-value; worktemp1=worktemp1-next; alloctemp=alloctemp-next; if(status=0) pathhead=path1=path2=(struct path*)malloc(pathlen); path1-next=path2-next=NULL; path1-value=i; status+; else path2=(struct path*)malloc(pathlen); pa
16、th2-value=i; if(status=1) pathhead-next=path2; status+; path1-next=path2; path1=path2; finishtemp-stat=1; else for(t=0;tnext; finishtemp-stat=0; else for(t=0;tnext; alloctemp=alloctemp-next; processtest=0; worktemp=workhead; finishtemp=finishtemp-next; path2-next=NULL; finishtemp=finihead; for(temp=
17、0;tempstat=0) printf(n系统处于非安全状态!n); exit(0); finishtemp=finishtemp-next; printf(n系统处于安全状态.n); printf(n安全序列为: n); do printf(p%d ,pathhead-value); while(pathhead=pathhead-next); printf(n); return 0; 运行结果:请输入系统资源的种类数:3请输入现时内存中的进程数:5请输入已分配资源矩阵:请输入已分配给进程 p0 的 A 种系统资源:0请输入已分配给进程 p0 的 B 种系统资源:1请输入已分配给进程 p0
18、 的 C 种系统资源:0请输入已分配给进程 p1 的 A 种系统资源:2请输入已分配给进程 p1 的 B 种系统资源:0请输入已分配给进程 p1 的 C 种系统资源:0请输入已分配给进程 p2 的 A 种系统资源:3请输入已分配给进程 p2 的 B 种系统资源:0请输入已分配给进程 p2 的 C 种系统资源:2请输入已分配给进程 p3 的 A 种系统资源:2请输入已分配给进程 p3 的 B 种系统资源:1请输入已分配给进程 p3 的 C 种系统资源:1请输入已分配给进程 p4 的 A 种系统资源:0请输入已分配给进程 p4 的 B 种系统资源:0请输入已分配给进程 p4 的 C 种系统资源:2
19、请输入最大需求矩阵:请输入进程 p0 种类 A 系统资源最大需求:7请输入进程 p0 种类 B 系统资源最大需求:5请输入进程 p0 种类 C 系统资源最大需求:3请输入进程 p1 种类 A 系统资源最大需求:3请输入进程 p1 种类 B 系统资源最大需求:2请输入进程 p1 种类 C 系统资源最大需求:2请输入进程 p2 种类 A 系统资源最大需求:9请输入进程 p2 种类 B 系统资源最大需求:0请输入进程 p2 种类 C 系统资源最大需求:2请输入进程 p3 种类 A 系统资源最大需求:2请输入进程 p3 种类 B 系统资源最大需求:2请输入进程 p3 种类 C 系统资源最大需求:2请输入进程 p4 种类 A 系统资源最大需求:4请输入进程 p4 种类 B 系统资源最大需求:3请输入进程 p4 种类 C 系统资源最大需求:3请输入现时系统剩余的资源矩阵:种类 A 的系统资源剩余:10种类 B 的系统资源剩余:5种类 C 的系统资源剩余:7系统处于安全状态.安全序列为:p0 p1 p2 p3 p4请按任意键继续. . .
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1