⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 process.java

📁 一个整体操作系统的主要功能的计算机模拟实现(含进程、内存与设备管理)
💻 JAVA
字号:
package design;
import java.util.*;
import java.io.*;
import design.*;

/**
 * <p>Title: 操作系统课程设计</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author 胡波
 * @version 1.0
 */

public class process extends Thread {
  String id;
  long limit_time;
  String state=new String("Ready");
  int prioprity;
  Date start_time=new Date();
  boolean limit_time_end=false;
  boolean resource_full=false;
  Memory m=new Memory();
  resource r;

  public void setID(String s){id=new String(s);}
  public void setLimit_time(long s){limit_time=s;}
  public boolean setState(String s){
    state=new String(s);
    return checkState();
  }
  public void setPrioprity(int p){prioprity=p;}
  public void iniMemory(int me){m.setSize(me);}
  public void distributeMemory(int a){m.setStartPose(a);}
  public void iniResource(int[] a){
    r.setResourceGeted(a);
    resource_full=r.sourceFull();
  }
  public void bestResource(int a[]){
    r.bestGet(a);
  }
  public void allResource(int a[]){
    r.allGet(a);
    resource_full=r.sourceFull();
  }
  public void addResource(){
    r.addResource();
    resource_full=r.sourceFull();
  }
  public String getID(){return id;}
  public int getRunnigtime(){
    Date d=new Date();
    return (int)(d.getTime()-start_time.getTime());
  }
  public String getState(){return state;}
  public int getPrioprity(){return prioprity;}
  public boolean resourceFull(){return resource_full;}
  public int getMemoryStart(){return m.getStartPose();}
  public int getMemorySize(){return m.getSize();}
  public int[] getResourceNeeded(){return r.resourceNeeded;}
  public int[] getResourceGetted(){return r.resourceGetted;}
  public int[] getResourceNoGetted(){return r.resourceNoGetted;}

  public process(int[] a,int memorySize) {
    r=new resource(a);
    m.setSize(memorySize);
  }
  public process(process p){//没有转移完全部数据
    new process(p.getResourceNeeded(),p.getMemorySize());
    this.r.setResourceGeted(p.r.resourceGetted);
    this.r.resourceNoGetted=p.r.resourceNoGetted;
    this.m.setStartPose(p.m.getStartPose());
    this.id=new String(p.getID());
    this.limit_time=p.limit_time;
    this.state=new String(p.getState());
    this.prioprity=p.getPrioprity();
    this.start_time=p.start_time;
    this.limit_time_end=p.limit_time_end;
    this.resource_full=p.resource_full;
  }

  public void run(){
    if(!resource_full)
      System.out.println("ERROR,进程运行时资源未分配足------process.run()");
    start_time=new Date();
    try{
      sleep(limit_time);
    }
    catch (Exception e){
      e.printStackTrace();
    }
    limit_time_end=true;
  }

  public boolean checkState(){
    if(state.toUpperCase().equals("RUNNING")||
       state.toUpperCase().equals("READY")||
       state.toUpperCase().equals("BLOCKED"))
      return true;
    System.out.println("ERROR,进程状态分配错误-------------process.checkState");
    return false;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -