public static void FIFO() { for (int timer = 0; timer >= 0; timer++) { for (int i = 0; i < processes.length; i++) { if (waitingQueue[0] == null && (i + 1) == processes.length && processes == null) { System.out.println("Out of processes, end of simulation."); return; } if ((waitingQueue[0] == null) && (i + 1) == processes.length && (runningProcess == 0) && i == processes.length) { System.out.println("No processes to run at time " + timer); } if ((timer == processes[i].getStartTime()) && (i + 1) == processes.length && (runningProcess == 0)) { runningProcess = 1; currentProcess = processes[i]; System.out.println( "Running process " + currentProcess.getProcessNumber() + " at time " + timer); } if (timer == processes[i].getStartTime() && (i + 1) == processes.length && runningProcess == 1) { sendToQueue(processes[i]); System.out.println( "Process running: process " + waitingQueue[0].getProcessNumber() + " is waiting at time " + timer); addWaitingTime(); } if (currentProcess != null && (i + 1) == processes.length && timer == (currentProcess.getStartTime() + currentProcess.getRunTime())) { System.out.println("Process " + currentProcess.getProcessNumber() + " finished"); runningProcess = 0; } } } }
public void sheduleFCFS() { Process newprocess = new Process(); Process min = newprocess; int Ttime = 0; while (processlist.size() > 0) { if (min == newprocess) { for (int i = 0; i < processlist.size() - 1; i++) { if (processlist.get(i).getStartTime() <= processlist.get(i + 1).getStartTime()) { min = processlist.get(i); } else { min = processlist.get(i + 1); } } } if (min.getServiceTime() == 0) { if (min != newprocess) { processlist.remove(min); min = newprocess; } } else if (min.getServiceTime() > 0) { if (min.getStartTime() <= Ttime) { timelist.add(min.getProcessId()); min.setServiceTime(min.getServiceTime() - 1); } else { timelist.add("Null"); } } Ttime++; } for (int k = 0; k < timelist.size(); k++) { System.out.print(timelist.get(k) + " "); } }