操作系统实验报告 进程管理 java编写相关的界面.doc_第1页
操作系统实验报告 进程管理 java编写相关的界面.doc_第2页
操作系统实验报告 进程管理 java编写相关的界面.doc_第3页
操作系统实验报告 进程管理 java编写相关的界面.doc_第4页
操作系统实验报告 进程管理 java编写相关的界面.doc_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

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

文档简介

操作系统实验报告 计算机学院 (院、系) 专业 班 组 课学号 20 姓名 Tracy 实验日期 教师评定 实验一 进程管理一、实验目的通过实验使学生进一步了解进程、进程状态、进程控制等基本概念。基本能达到下列具体的目标:1.理解进程 PCB 的概念,以及 PCB 如何实现、如何组织以及管理。2.复习数据结构中如何对链的操作,包括建链、删除、插入结点等,来实现进程的管理。二、实验内容1、 建立一个结点,即 PCB 块包括用户标识域、状态域(执行、等待、就绪)、 link 域。2、 建立三个队列(执行队列、就绪队列、等待队列)。3、 根据进程状态转换实现对三个队列的具体操作。具体的驱动可以采用时间片算法或手动调度的形式完成三个状态之间的转换4、 用java编写相关的界面。三、实验步骤1.通过java的awt和swing包进行相关界面的布局,相关代码为: Panel p1=new Panel(new FlowLayout(FlowLayout.LEFT);Panel p2=new Panel(new FlowLayout();/三个显示进程的文本框JTextField readyList,runningList,waitingList,input;/三个进程的链表ArrayList reList=new ArrayList();ArrayList ruList=new ArrayList();ArrayList waList=new ArrayList();Iterator iterRunning,iterReady,iterWaiting;public MyFrame()this.setLayout(new BorderLayout();this.add(p1,BorderLayout.NORTH);this.add(p2,BorderLayout.CENTER);init();this.setTitle(进程三态转换);setBounds(300,300,500,300);setVisible(true);void init()Box box1=Box.createHorizontalBox();box1.add(new JLabel(进程就绪队列:);readyList=new JTextField(35);readyList.setEditable(false);box1.add(readyList);Box box2=Box.createHorizontalBox();box2.add(new JLabel(进程阻塞队列:);waitingList=new JTextField(35);waitingList.setEditable(false);box2.add(waitingList);Box box3=Box.createHorizontalBox();box3.add(new JLabel(进程运行队列:);runningList=new JTextField(35);runningList.setEditable(false);box3.add(runningList);Box baseBox1=Box.createVerticalBox();baseBox1.add(box1);baseBox1.add(Box.createVerticalStrut(10);baseBox1.add(box2);baseBox1.add(Box.createVerticalStrut(10);baseBox1.add(box3);p1.add(baseBox1);Button b1=new Button(执行就绪);Button b2=new Button(就绪执行);Button b3=new Button(执行阻塞);Button b4=new Button(阻塞就绪);Button exit=new Button(清空所有进程);this.add(exit,BorderLayout.SOUTH);b1.addActionListener(new readyListener();b2.addActionListener(new runningListener();b3.addActionListener(new waitingListener();b4.addActionListener(new ready2Listener();exit.addActionListener(new clearListener();Box box4=Box.createHorizontalBox();box4.add(b1);box4.add(b2);Box box5=Box.createHorizontalBox();box5.add(b3);box5.add(b4);Box box6=Box.createHorizontalBox();input=new JTextField(20);input.addActionListener(new inputListener();box6.add(new Label(请输入进程名字,按回车确认);box6.add(input);Box baseBox2=Box.createVerticalBox();baseBox2.add(box6);baseBox2.add(Box.createVerticalStrut(10);baseBox2.add(box4);baseBox2.add(Box.createVerticalStrut(10);baseBox2.add(box5);p2.add(baseBox2);运行的总体界面如下图所示:图1 总体布局2.分别为“执行就绪”,“就绪执行”,“执行阻塞”,“阻塞就绪”四个按钮添加监听器,监听队列的三种状态。输入进程也要相关的监听器。输入进程名字的监听器主要代码:class inputListener implements ActionListener String s = ;public void actionPerformed(ActionEvent e) if (input.getText().equals() JOptionPane.showMessageDialog(null, 请输入进程名字, 警告对话框,JOptionPane.WARNING_MESSAGE); else Process newPro = new Process();newPro.setName(input.getText();reList.add(newPro);/ 把输入的进程放进就绪队列s = readyList.getText();readyList.setText(s + newPro.getName() + );input.setText();当输入的进程名字为空时,弹出警告输入框:图2 进程名字不能为空输入正确显示在就绪队列中(名字分别为:“第一个进程”,“第二个进程”,第三个进程):图3 输入三个进程后就绪到执行状态的监听器主要代码:class runningListener implements ActionListener public void actionPerformed(ActionEvent e) iterReady = reList.iterator();iterRunning = ruList.iterator();String s = ;if (iterReady.hasNext() / 当就绪进程不为空而且没有进程运行时if (iterRunning.hasNext() = false) / 把就绪的第一个进程变为运行状态Process newPro = reList.remove(0);ruList.add(newPro);runningList.setText(newPro.getName();/ 重新输出就绪状态iterReady = reList.iterator();while (iterReady.hasNext() Process Pro = iterReady.next();s = s.concat(Pro.getName().concat( );readyList.setText(s); else JOptionPane.showMessageDialog(null, 已有进程运行中,不能进行该操作,警告对话框, JOptionPane.WARNING_MESSAGE); else JOptionPane.showMessageDialog(null, 没有任何进程在就绪队列中,不能进行该操作,警告对话框, JOptionPane.WARNING_MESSAGE);当就绪队列为空时:图4 就绪态没有任何进程就绪队列有进程时,单机“就绪执行”按钮:图5 就绪执行当有进程在运行时:图6 已有进程运行执行到阻塞状态的监听器主要代码:class waitingListener implements ActionListener public void actionPerformed(ActionEvent e) iterRunning = ruList.iterator();iterWaiting = waList.iterator();if (iterRunning.hasNext() = false) JOptionPane.showMessageDialog(null, 没有正在执行的进程, 警告对话框,JOptionPane.WARNING_MESSAGE); else Process newPro = ruList.remove(0);waList.add(newPro);runningList.setText( );/ 重新读取阻塞的进程iterWaiting = waList.iterator();String s = ;while (iterWaiting.hasNext() Process Pro = iterWaiting.next();s = s.concat(Pro.getName().concat( );waitingList.setText(s);执行队列有进程执行是,单击“执行阻塞”:图7 执行到阻塞状态执行队列没进程,弹出警告对话框:图8 没有进程执行执行到就绪态监听器主要代码:class readyListener implements ActionListener public void actionPerformed(ActionEvent e) iterRunning = ruList.iterator();iterReady = reList.iterator();if (iterRunning.hasNext() = false) JOptionPane.showMessageDialog(null, 没有正在执行的进程, 警告对话框,JOptionPane.WARNING_MESSAGE); else Process newPro = ruList.remove(0);reList.add(newPro);runningList.setText( );/ 重新读取就绪的进程iterReady = reList.iterator();String s = ;while (iterReady.hasNext() Process Pro = iterReady.next();s = s.concat(Pro.getName().concat( );readyList.setText(s);没有进程在执行,弹出警告对话框:图9 没有进程执行执行队列有进程执行是,单击“执行就绪”:图10 执行到就绪阻塞到就绪态监听器主要代码:class ready2Listener implements ActionListener public void actionPerformed(ActionEvent e) iterReady = reList.iterator();iterWaiting = waList.iterator();if (iterWaiting.hasNext() = false) JOptionPane.showMessageDialog(null, 没有阻塞的进程, 警告对话框,JOptionPane.WARNING_MESSAGE); else Process newPro = waList.remove(0);reList.add(newPro);/ 重新读取阻塞的进程iterWaiting = waList.iterator();String s = ;while (iterWaiting.hasNext() Process Pro = iterWaiting.next();s = s.concat(Pro.getName().concat( );waitingList.setText(s);/ 重新读取就绪的进程iterReady = reList.iterator();String t = ;while (iterReady.hasNext() Process Pro = iterReady.next();t = t.concat(Pro.getName().concat( );readyLis

温馨提示

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

评论

0/150

提交评论