操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx

上传人:聆听****声音 文档编号:272989 上传时间:2023-04-28 格式:DOCX 页数:20 大小:523.74KB
下载 相关 举报
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第1页
第1页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第2页
第2页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第3页
第3页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第4页
第4页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第5页
第5页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第6页
第6页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第7页
第7页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第8页
第8页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第9页
第9页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第10页
第10页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第11页
第11页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第12页
第12页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第13页
第13页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第14页
第14页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第15页
第15页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第16页
第16页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第17页
第17页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第18页
第18页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第19页
第19页 / 共20页
操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx

《操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx》由会员分享,可在线阅读,更多相关《操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx(20页珍藏版)》请在冰点文库上搜索。

操作系统实验报告-利用银行家算法避免死锁Word文档格式.docx

①工作向量Work。

它表示系统可提供进程继续运行所需要的各类资源数目,执行安全算法开始时,Work=Allocation;

②布尔向量Finish。

它表示系统是否有足够的资源分配给进程,使之运行完成,开始时先做Finish[i]=false,当有足够资源分配给进程时,令Finish[i]=true。

(2)从进程集合中找到一个能满足下述条件的进程:

①Finish[i]=false

②Need<

or=Work

如找到,执行步骤(3);

否则,执行步骤(4)。

(3)当进程P获得资源后,可顺利执行,直至完成,并释放出分配给它的资源,故应执行:

Work=Work+Allocation;

Finish[i]=true;

转向步骤

(2)。

(4)如果所有进程的Finish[i]=true,则表示系统处于安全状态;

否则,系统处于不安全状态。

4、流程图:

系统主要过程流程图

银行家算法流程图

安全性算法流程图

5、主要数据结构

假设有M个进程N类资源,则有如下数据结构:

intmax[M*N]M个进程对N类资源的最大需求量

intavailable[N]系统可用资源数

intallocated[M*N]M个进程已经得到N类资源的资源量

intneed[M*N]M个进程还需要N类资源的资源量

intworked[]系统提供给进程继续运行所需的各类资源数目

四、源代码

importjava.awt.*;

importjavax.swing.*;

importjava.util.*;

importjava.awt.event.*;

importjavax.swing.border.*;

publicclassOsBankerextendsJFrame{//界面设计JLabellabelInfo;

JLabellabelInfo1;

intresourceNum,processNum;

intcount=0;

JButtonbuttonRequest,buttonSetInit,button,button1,buttonsearch,button2;

JTextFieldtf1,tf2;

JTextField[]textAvailable;

JTextField[][]textAllocation;

JTextField[][]textNeed;

JTextFieldtextProcessName;

JTextField[]textRequest;

intavailable[];

intmax[][];

intneed[][];

intallocated[][];

intSafeSequence[];

intrequest[];

booleanFinish[];

intworked[];

booleanflag=false;

JFramef1;

JFramef2;

JFramef3;

JTextAreajt;

voiddisplay(){

Borderborder=BorderFactory.createLoweredBevelBorder();

BorderborderTitled=BorderFactory.createTitledBorder(border,"

按钮区"

);

textAvailable=newJTextField[5];

textAllocation=newJTextField[6][5];

textNeed=newJTextField[6][5];

textProcessName=newJTextField("

"

textProcessName.setEnabled(false);

textRequest=newJTextField[5];

tf1=newJTextField(20);

tf2=newJTextField(20);

labelInfo=newJLabel("

请先输入资源个数和进程个数(1~6),后单击确定"

JPanelcontentPane;

contentPane=(JPanel)this.getContentPane();

contentPane.setLayout(null);

contentPane.setBackground(Color.pink);

labelInfo.setBounds(50,10,300,40);

labelInfo.setOpaque(true);

labelInfo.setForeground(Color.red);

labelInfo.setBackground(Color.pink);

contentPane.add(labelInfo,null);

JLabelb1=newJLabel("

资源个数:

b1.setForeground(Color.blue);

JLabelb2=newJLabel("

进程个数:

b2.setForeground(Color.blue);

b1.setBounds(50,80,80,30);

contentPane.add(b1,null);

tf1.setBounds(180,80,170,30);

contentPane.add(tf1,null);

b2.setBounds(50,150,80,30);

contentPane.add(b2,null);

tf2.setBounds(180,150,170,30);

contentPane.add(tf2,null);

button1=newJButton("

确定"

button=newJButton("

重置"

button1.setBounds(80,200,80,30);

contentPane.add(button1,null);

button.setBounds(220,200,80,30);

contentPane.add(button,null);

this.setSize(400,300);

this.setResizable(false);

this.setTitle("

银行家算法(SXJ)"

this.setLocationRelativeTo(null);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.setVisible(true);

f1=newJFrame();

labelInfo1=newJLabel("

请先输入最大需求和分配矩阵,然后单击初始化"

JPanelcontentPane1;

contentPane1=(JPanel)f1.getContentPane();

contentPane1.setLayout(null);

contentPane1.setBackground(Color.pink);

labelInfo1.setOpaque(true);

labelInfo1.setBounds(75,10,400,40);

labelInfo1.setBackground(Color.pink);

labelInfo1.setForeground(Color.blue);

contentPane1.add(labelInfo1,null);

JLabellabelAvailableLabel=newJLabel("

AllResource:

JLabellabelNeedLabel=newJLabel("

MaxNeed:

JLabellabelAllocationLabel=newJLabel("

allocated:

JLabellabelRequestLabel=newJLabel("

requestprocess:

labelNeedLabel.setBounds(75,90,100,20);

//x,y,width,heightcontentPane1.add(labelNeedLabel,null);

labelAllocationLabel.setBounds(75,240,100,20);

contentPane1.add(labelAllocationLabel,null);

labelAvailableLabel.setBounds(75,70,100,20);

contentPane1.add(labelAvailableLabel,null);

labelRequestLabel.setBounds(75,400,100,20);

contentPane1.add(labelRequestLabel,null);

JLabel[]labelProcessLabel1={newJLabel("

进程1"

),newJLabel("

进程2"

进程3"

进程4"

进程5"

进程6"

)};

JLabel[]labelProcessLabel2={newJLabel("

JPanelpPanel1=newJPanel(),pPanel2=newJPanel(),pPanel3=newJPanel(),pPanel4=newJPanel();

pPanel1.setLayout(null);

pPanel2.setLayout(null);

/*

*pPanel4.setLayout(null);

pPanel4.setBounds(440,120,90,270);

*pPanel4.setBorder(borderTitled);

*/

buttonSetInit=newJButton("

初始化"

buttonsearch=newJButton("

检测安全性"

button2=newJButton("

buttonRequest=newJButton("

请求资源"

buttonSetInit.setBounds(420,140,100,30);

contentPane1.add(buttonSetInit,null);

buttonsearch.setBounds(420,240,100,30);

contentPane1.add(buttonsearch,null);

button2.setBounds(420,340,100,30);

contentPane1.add(button2,null);

buttonRequest.setBounds(420,425,100,30);

contentPane1.add(buttonRequest,null);

for(intpi=0;

pi<

6;

pi++){

labelProcessLabel1[pi].setBounds(0,0+pi*20,60,20);

labelProcessLabel2[pi].setBounds(0,0+pi*20,60,20);

}

pPanel1.setBounds(75,120,60,120);

pPanel2.setBounds(75,270,60,120);

pi++){pPanel1.add(labelProcessLabel1[pi],null);

pPanel2.add(labelProcessLabel2[pi],null);

}contentPane1.add(pPanel1);

contentPane1.add(pPanel2);

contentPane1.add(pPanel4);

for(intsi=0;

si<

5;

si++)

pi++){textNeed[pi][si]=newJTextField();

textNeed[pi][si]

.setBounds(150+si*50,120+pi*20,50,20);

textNeed[pi][si].setEditable(false);

textAllocation[pi][si]=newJTextField();

textAllocation[pi][si].setBounds(150+si*50,270+pi*20,50,20);

textAllocation[pi][si].setEditable(false);

si++){textAvailable[si]=newJTextField();

textAvailable[si].setEditable(false);

textAvailable[si].setBounds(150+si*50,70,50,20);

textRequest[si]=newJTextField();

textRequest[si].setEditable(false);

textRequest[si].setBounds(150+si*50,430,50,20);

contentPane1.add(textAvailable[si],null);

contentPane1.add(textRequest[si],null);

pi++)

si++){contentPane1.add(textNeed[pi][si],null);

contentPane1.add(textAllocation[pi][si],null);

textProcessName.setBounds(80,430,50,20);

contentPane1.add(textProcessName,null);

f1.setSize(550,500);

f1.setResizable(false);

f1.setTitle("

f1.setLocationRelativeTo(null);

f1.setDefaultCloseOperation(EXIT_ON_CLOSE);

//f1.setVisible(true);

f1.setVisible(false);

f2=newJFrame("

安全序列显示框"

jt=newJTextArea(75,40);

jt.setBackground(Color.pink);

jt.setForeground(Color.blue);

JScrollPanescrollPane=newJScrollPane(jt);

//加滚动条scrollPane.setBorder(BorderFactory.createLoweredBevelBorder());

//边界(f2.getContentPane()).add(scrollPane);

f2.setSize(450,400);

f2.setResizable(false);

f2.setDefaultCloseOperation(EXIT_ON_CLOSE);

f2.setVisible(false);

buttonSetInit.setEnabled(false);

buttonRequest.setEnabled(false);

buttonsearch.setEnabled(false);

button1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){

化按钮"

//labelInfo.setText("

请先初始化allocated和Maxneed,后单击初始

f1.setVisible(true);

buttonSetInit.setEnabled(true);

resourceNum=Integer.parseInt(tf1.getText());

processNum=Integer.parseInt(tf2.getText());

for(inti=0;

i<

processNum;

i++){

for(intj=0;

j<

resourceNum;

j++){textNeed[i][j].setEditable(true);

textAllocation[i][j].setEditable(true);

textAvailable[j].setEditable(true);

});

buttonSetInit.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){

Init();

buttonsearch.setEnabled(true);

buttonsearch.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEvente){count=0;

SafeSequence=newint[processNum];

worked=newint[resourceNum];

Finish=newboolean[processNum];

copyVector(worked,available);

Safety(0);

jt.append("

安全序列数量:

+count);

if(flag){

labelInfo1.setText("

当前系统状态:

安全"

f2.setVisible(true);

buttonRequest.setEnabled(true);

textProcessName.setEnabled(true);

for(inti=0;

i++){textRequest[i].setEditable(true);

}else{

不安全"

}buttonSetInit.setEnabled(false);

buttonRequest.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){

count=0;

i++){Finish[i]=false;

}jt.setText("

flag=false;

RequestResource();

button2.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){

*tf1.setText("

tf2.setText("

*/f2.setVisible(false);

jt.setText("

processN

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2