银行家算法(操作系统实验报告).doc_第1页
银行家算法(操作系统实验报告).doc_第2页
银行家算法(操作系统实验报告).doc_第3页
银行家算法(操作系统实验报告).doc_第4页
银行家算法(操作系统实验报告).doc_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实 验 报 告 课程名称: 计算机操作系统 实验名称: 银行家算法 _ 任课教师: 霍 林 专 业: 计算机科学与技术 班 级: 学 号: _姓 名:蓝冠恒_ _ 完成日期: 2009年10月15日 一、实验目的:加深对操作系统的进程管理与资源分配了解,深刻理解系统安全性检验算法。二、主要实验内容及要求: 实验内容 :利用银行家算法检验系统的安全性。实验要求 :1.输入系统进程数量n和资源类型数量m。 2.输入每类资源的数量。 3.输入每个进程每类资源的最大需求量和已获资源量。 4.检验系统的安全系。三、实验结果与结论:(经调试正确的源程序和程序的运行结果)编程员:蓝冠恒程序源代码:package disFace;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.StackLayout;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;import org.eclipse.ui.forms.widgets.FormToolkit;import com.swtdesigner.SWTResourceManager;public class DisFace protected Shell shell;private final FormToolkit formToolkit = new FormToolkit(Display.getDefault();private Composite composite;private Label label;private Label label_1;private Text processN;private Text kindM;private Button button1;private Text listText;/输出文本框private Composite composite4;private Label label_3;private Text kindNumbers; /资源数量输入框private Button button2;private Text theKind1;private Label label_5;private Label label_6;private Text MaxText; /最大资源需求输入框private Text AllocationText;/已获资源输入框private Button button3;private Label label_7;private Text theProcess;private Text theKind2;private Label label_11;private Button test;private int N;/进程数量private int M;/资源类型数量int Max;/进程最大资源需求数组int Allocation;/进程已获资源数组int Need;/进程所需资源数组int Available;/起初可用资源数组int Work; /可提供资源数组boolean Finish;/进程完成标识int i=0;int j=0;int k=0;private Composite composite1;StackLayout stackLayout=new StackLayout();StackLayout stackLayout2=new StackLayout();private Composite composite3;private Composite composite2;private Composite composite0;public static void main(String args) try DisFace window = new DisFace();window.open(); catch (Exception e) e.printStackTrace();public void open() Display display = Display.getDefault();createContents();shell.open();shell.layout();while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep();protected void createContents() shell = new Shell();shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND);shell.setText(银行家算法实现);shell.setSize(733, 565);/*-面板-*/composite = new Composite(shell, SWT.BORDER);composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN);composite.setBounds(10, 10, 697, 492);composite.setData(name, composite);formToolkit.adapt(composite);formToolkit.paintBordersFor(composite);composite0 = new Composite(composite, SWT.NONE);composite0.setBounds(0, 1, 210, 156);composite0.setData(name, composite0);formToolkit.adapt(composite0);formToolkit.paintBordersFor(composite0);composite1 = new Composite(composite, SWT.NONE);composite1.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN);composite1.setBounds(210, 1, 224, 156);composite1.setData(name, composite1);formToolkit.adapt(composite1);formToolkit.paintBordersFor(composite1);composite1.setLayout(stackLayout);composite2 = new Composite(composite1, SWT.BORDER);composite2.setBackgroundMode(SWT.INHERIT_FORCE);composite2.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE);composite2.setBackground(SWTResourceManager.getColor(0, 255, 0);composite2.setData(name, composite2);formToolkit.adapt(composite2);formToolkit.paintBordersFor(composite2);composite3 = new Composite(composite, SWT.NONE);composite3.setBounds(434, 1, 263, 156);composite3.setData(name, composite3);formToolkit.adapt(composite3);formToolkit.paintBordersFor(composite3);composite3.setLayout(stackLayout2);composite4 = new Composite(composite3, SWT.BORDER);composite4.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);composite4.setData(name, composite4);formToolkit.adapt(composite4);formToolkit.paintBordersFor(composite4);/*-标签-*/label_3 = new Label(composite2, SWT.HORIZONTAL);label_3.setBounds(59, 26, 78, 26);label_3.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);label_3.setData(name, label_3);formToolkit.adapt(label_3, true, true);label_3.setText(资源数量为);label_5 = new Label(composite4, SWT.NONE);label_5.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);label_5.setBounds(0, 55, 112, 26);label_5.setData(name, label_5);formToolkit.adapt(label_5, true, true);label_5.setText(最大资源需求量);label_6 = new Label(composite4, SWT.NONE);label_6.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);label_6.setBounds(0, 87, 112, 26);label_6.setData(name, label_6);formToolkit.adapt(label_6, true, true);label_6.setText(已获资源数量);label_7 = new Label(composite4, SWT.NONE);label_7.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);label_7.setBounds(0, 23, 46, 26);label_7.setData(name, label_7);formToolkit.adapt(label_7, true, true);label_7.setText(进 程);label_11 = new Label(composite4, SWT.NONE);label_11.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);label_11.setBounds(80, 23, 50, 26);label_11.setData(name, label_11);formToolkit.adapt(label_11, true, true);label_11.setText(对资源);label_1 = new Label(composite0, SWT.NONE);label_1.setBounds(10, 65, 80, 23);label_1.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);label_1.setData(name, label_1);formToolkit.adapt(label_1, true, true);label_1.setText(资源类量m);label = new Label(composite0, SWT.NONE);label.setBounds(10, 24, 80, 23);label.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);label.setData(name, label);formToolkit.adapt(label, true, true);label.setText(进程数量n);/*-文本-*/theKind1 = new Text(composite2, SWT.READ_ONLY | SWT.CENTER | SWT.MULTI);theKind1.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE);theKind1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);theKind1.setBounds(22, 26, 31, 26);theKind1.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);theKind1.setData(name, theKind1);formToolkit.adapt(theKind1, true, true);theKind1.setText(R+String.valueOf(0);listText = new Text(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);listText.setCapture(true);listText.setForeground(SWTResourceManager.getColor(0, 0, 0);listText.setBackground(SWTResourceManager.getColor(51, 255, 255);listText.setBounds(0, 163, 696, 325);listText.setData(name, text_2);formToolkit.adapt(listText, true, true);kindNumbers = new Text(composite2, SWT.BORDER | SWT.CENTER);kindNumbers.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);kindNumbers.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN);kindNumbers.setBounds(143, 29, 38, 23);kindNumbers.setData(name, kindNumbers);formToolkit.adapt(kindNumbers, true, true);MaxText = new Text(composite4, SWT.BORDER | SWT.CENTER);MaxText.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);MaxText.setBounds(118, 56, 61, 23);MaxText.setData(name, MaxText);formToolkit.adapt(MaxText, true, true);AllocationText = new Text(composite4, SWT.BORDER | SWT.CENTER);AllocationText.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);AllocationText.setForeground(SWTResourceManager.getColor(SWT.COLOR_GREEN);AllocationText.setBounds(118, 87, 61, 23);AllocationText.setData(name, AllocationText);formToolkit.adapt(AllocationText, true, true);theProcess = new Text(composite4, SWT.READ_ONLY | SWT.CENTER);theProcess.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);theProcess.setBounds(52, 23, 22, 26);theProcess.setData(name, theProcess);formToolkit.adapt(theProcess, true, true);theProcess.setText(P+String.valueOf(0);theKind2 = new Text(composite4, SWT.READ_ONLY | SWT.CENTER);theKind2.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);theKind2.setBounds(136, 23, 43, 26);theKind2.setData(name, theKind2);formToolkit.adapt(theKind2, true, true);theKind2.setText(R+String.valueOf(0);processN = new Text(composite0, SWT.BORDER);processN.setBackground(SWTResourceManager.getColor(0, 255, 0);processN.setBounds(107, 21, 73, 23);processN.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);processN.setData(name, text);formToolkit.adapt(processN, true, true);kindM = new Text(composite0, SWT.BORDER);kindM.setBounds(107, 65, 73, 23);kindM.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);kindM.setData(name, text_1);formToolkit.adapt(kindM, true, true);/*-按钮-*/button1 = new Button(composite0, SWT.NONE);button1.setForeground(SWTResourceManager.getColor(0, 255, 0);button1.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN);button1.setBounds(107, 115, 72, 31);button1.addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) button1Event(););button1.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);button1.setData(name, button);formToolkit.adapt(button1, true, true);button1.setText(确定);button2 = new Button(composite2, SWT.NONE);button2.setBackground(SWTResourceManager.getColor(50, 205, 50);button2.setForeground(SWTResourceManager.getColor(SWT.COLOR_GREEN);button2.setBounds(107, 114, 74, 32);button2.addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) button2Event(););button2.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);button2.setData(name, button_1);formToolkit.adapt(button2, true, true);button2.setText(确定);button3 = new Button(composite4, SWT.NONE);button3.addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) button3Event(););button3.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);button3.setBounds(114, 116, 65, 32);button3.setData(name, button_2);formToolkit.adapt(button3, true, true);button3.setText(确定);test = new Button(shell, SWT.NONE);test.setBounds(627, 502, 80, 27);test.setSelection(true);test.addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) TestEvent(););test.setFont(SWTResourceManager.getFont(微软雅黑, 12, SWT.NORMAL);test.setData(name, button_3);formToolkit.adapt(test, true, true);test.setText(立刻检验);/定义创建相关数组函数public void Create(int n,int m) Max=new intnm; /创建最大资源需求量数组 Allocation=new intnm;/创建已获资源量数组 Need=new intnm; /创建需要资源量数组 Available=new intm; /创建可用资源量数组 Work=new intm; /创建可供资源量数组 Finish=new booleann; /创建进程可否完成标识数组 listText.insert(进程); for(int h=0;h4;h+)listText.insert(资源类型);printReKind();listText.insert(n);/定义打印资源类型的函数public void printReKind()for(int h=0;hM;h+)if(h10)listText.insert(String.valueOf(R+h+ );else listText.insert(String.valueOf(R+h+ );/定义button1的事件函数public void button1Event()N=Integer.parseInt(processN.getText();M=Integer.parseInt(kindM.getText();Create(N,M); /调用Create(n,m)方法stackLayout.topControl=composite2;composite1.layout();composite0.setEnabled(false);/定义button2的事件函数,设定进程每类资源的数量public void button2Event()if(iM)Availablei=Integer.parseInt(kindNumbers.getText();kindNumbers.setText();i+;if(i!=M)theKind1.setText(R+String.valueOf(i);if(i=M)stackLayout2.topControl=composite4;composite3.layout();composite2.setEnabled(false);/定义button3的事件函数public void button3Event()if(jN)if(kM)Maxjk=Integer.parseInt(MaxText.getText();Allocationjk=Integer.parseInt(AllocationText.getText();MaxText.setText();AllocationText.setText();Needjk=Maxjk-Allocationjk;Availablek=Availablek-Allocationjk;k+;if(k=M)k=0; j+;Work=Available; if(jN) theProcess.setText(P+String.valueOf(j); theKind2.setText(R+String.valueOf(k); /如果输入完成,则输出刚输入的信息if(j=N&k=0)composite4.setEnabled(false);for(j=0;jN;j+)listText.insert( P+String.valueOf(j)+:);listText.insert(最大需求);for(int h=0;hM;h+)if(Maxjh10)listText.insert(String.valueOf(Maxjh)+ );else listText.insert(String.valueOf(Maxjh+ );listText.insert(已获资源);for(int h=0;hM;h+) if(Allocationjh10)listText.insert(String.valueOf(Allocationjh+ );else listText.insert(String.valueOf(Allocationjh+ ); listText.insert(需要资源);for(int h=0;hM;h+)if(Needjh10)listText.insert(String.valueOf(Needjh+ );else listText.insert(String.valueOf(Needjh+ );listText.insert(可用资源);for(int h=0;hM;h+) if(Availableh10)listText.insert(String.valueOf(Availableh+ );else listText.inser

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论