-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScheduler.java
76 lines (67 loc) · 2.49 KB
/
Scheduler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
*
* @Course : Operating Systems , Lab 2
* @Author : Sanchit Mehta<[email protected]>
* @Desc: Main class that scans input and calls
* all Schedulers
*
*/
import java.util.*;
import java.io.*;
public class Scheduler {
private String fileName;
private ArrayList <Process> procs = new ArrayList <>();
private static int time, running, cpuBurst;
private static int[] blocked;
private static int[] bursts;
private static BufferedReader br;
private static boolean isDone, verbose = false;
public Scheduler(String inputFile,String algo,Boolean detailedOP) throws Exception {
this.fileName = inputFile;
readInput();
System.out.println("\n\n");
switch(algo.toLowerCase()){
case "fcfs":
FCFS f = new FCFS(procs,detailedOP);
break;
case "sjf":
SJS sj = new SJS(procs,detailedOP);
break;
case "rr":
RoundRobin rr = new RoundRobin(procs,false);
break;
case "uni":
UniProgrammed up = new UniProgrammed(procs,detailedOP);
break;
}
System.out.println("\n\n");
}
public void readInput() throws Exception {
File f = new File(fileName);
Scanner sc = new Scanner(f);
String input = sc.nextLine();
System.out.println("\n");
input = input.replaceAll("\\(", "").replaceAll("\\)", "");
String[] inputs = input.split("\\s+");
int noOfProcesses = Integer.parseInt(inputs[0]);
for (int i = 1; i < noOfProcesses * 4; i = i + 4) {
Process p = new Process(Integer.parseInt(inputs[i]),
Integer.parseInt(inputs[i + 1]),
Integer.parseInt(inputs[i + 2]),
Integer.parseInt(inputs[i + 3]),
i-1);
procs.add(p);
}
Collections.sort(procs);
}
public static void main(String args[]) {
if (args.length != 3)
throw new IllegalArgumentException("Exactly 3 parameters required : <Input File Name> <SchedulingAlgo: (fcfs,sjf,rr,uni)> <Detailed-OP : (0,1)>");
try {
Scheduler s = new Scheduler(args[0],args[1],args[2].equals("1")?true:false);
} catch (Exception e) {
System.out.println(e);
System.out.println("Erooorrr");
}
}
}