操作系统实验二

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

广州大学学生实验报告

开课学院及实验室:计算机学院,电子信息楼416A室 2014年 11 月 27日

一、实验目的

通过对银行家算法进行验证,了解linux系统对死锁处理的机制。

二、使用仪器、器材

微机一台

操作系统:Ubuntu

三、实验内容

验证银行家算法进行

四、实验过程原始数据记录

实验代码

/* 银行家算法,操作系统概念(OS concepts Six Edition)

reedit by Johnny hagen,SCAU,run at vc6.0

*/

#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 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;

};

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,*needtemp;

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;i

{

for (j=0;j

{

printf("请输入已分配给进程p%d 的%c 种系统资源:",i,'A'+j); if(status==0)

{

allochead=alloc1=alloc2=(struct allocation*)malloc(alloclen); alloc1->next=alloc2->next=NULL;

scanf("%d",&allochead->value);

status++;

}

else

{

alloc2=(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;i

{

for (j=0;j

{

printf("请输入进程p%d 种类%c 系统资源最大需求:",i,'A'+j); if(status==0)

{

maxhead=maxium1=maxium2=(struct max*)malloc(maxlen); maxium1->next=maxium2->next=NULL;

scanf("%d",&maxium1->value);

status++;

}

else

{

maxium2=(struct max *)malloc(maxlen);

scanf("%d,%d",&maxium2->value);

if(status==1)

{

maxhead->next=maxium2;

相关文档
最新文档