实验报告
实验目的:
就绪进程数大于处理机数时,按照某种策略决定哪些进程优先占用处理机。实验模拟处理机调度,加深对处理机调度的理解。
实验内容:
实验一模拟短进程优先调度
进程8 个,到达时间和服务时间(用户输入)
至少两种结果: 1 到达时间:0,1,2,….
2 到达时间:其他
实验源代码
//进程类
public class Process {
String processName; //进程名称
int arrivalTime; //到达时间
int starTime; //开始时间
int finishTime; //实际完成时间
int wholeTime; //运行所需要的的时间;
public String getProcessName() {
return processName;
}
public int getStarTime() {
return starTime;
}
public int getFinishTime() {
return finishTime;
}
public int getArrivalTime() {
return arrivalTime;
}
public void setFinishTime(int finishTime) {
this.finishTime = finishTime;
}
public void setStarTime(int starTime) {
this.starTime = starTime;
}
public int getWholeTime() {
return wholeTime;
}
public Process(String processName, int arrivalTime, int wholeTime) {
this.processName = processName;
this.arrivalTime = arrivalTime;
this.wholeTime = wholeTime;
}
}
public class Short_process {
public static void main(String[] args) {
ArrayList<Process> arrayList = new ArrayList<>();
Scanner in = new Scanner(System.in);
System.out.println("请输入有几个进程呢?");
int numberofprocess = in.nextInt();
for (int i = 0 ; i<numberofprocess;i++)
{
System.out.println("请输入进程"+(i+1)+"的进程名称");
String name = in.next();
System.out.println("请输入进程"+(i+1)+"的到达时间");
int arrivalTime = in.nextInt();
System.out.println("请输入进程"+(i+1)+"的运行所需时间");
int wholeTime = in.nextInt();
Process process = new Process(name,arrivalTime,wholeTime);
arrayList.add(process);
//System.out.println("----------------------------");
}
test(arrayList);
}
public static void