1、实 验 报 告 课程名称: 计算机操作系统 实验名称: 银行家算法 _ 任课教师: 霍 林 专 业: 计算机科学与技术 班 级: 学 号: _姓 名:蓝冠恒_ _ 完成日期: 2009年10月15日 一、实验目的:加深对操作系统的进程管理与资源分配了解,深刻理解系统安全性检验算法。二、主要实验内容及要求: 实验内容 :利用银行家算法检验系统的安全性。实验要求 :1.输入系统进程数量n和资源类型数量m。 2.输入每类资源的数量。 3.输入每个进程每类资源的最大需求量和已获资源量。 4.检验系统的安全系。三、实验结果与结论:(经调试正确的源程序和程序的运行结果)编程员:蓝冠恒程序源代码:packa
2、ge 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
3、.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.get
4、Default();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 theKind
5、1;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;/进程最
6、大资源需求数组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 com
7、posite2;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 (!d
8、isplay.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(SWTRes
9、ourceManager.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
10、);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);form
11、Toolkit.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
12、);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(composite
13、3);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(SWTResource