-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOS.java
More file actions
97 lines (62 loc) · 2.16 KB
/
OS.java
File metadata and controls
97 lines (62 loc) · 2.16 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.io.File;
import java.io.FileWriter;
import java.util.*;
public class OS
{ double hdSize = (int) 2E6; // in KB
double ramSize = (int) 192E3; // in KB
Queue<PCB> ready = new LinkedList<>();
PriorityQueue<Job> jobs;
Input input;
int n; // number of jobs
int max;
int min;
int total;
public OS()
{ System.out.println("\t-- Simulation intialized -- \n");
input = new Input();
input.generateInput();
input.fillJQueue();
max = input.max;
min = input.min;
total = input.total;
n = input.n;
jobs = new PriorityQueue<>(n, new JobComparator());
System.out.printf("\t-- %d Jobs generated -- \n\n", n);
System.out.printf("\t-- Total required memory: %d KB -- \n\n\t-- RAM = %d KB --\n\n", total, (int) ramSize); }
public void JobScheduler()
{ if(input.jobs.size() > 0)
{ System.out.println("\t-- Filling Job Queue -- \n");
while(hdSize > 0 && input.jobs.size() > 0)
{ Job obj= input.jobs.poll();
jobs.add(obj);
hdSize -= obj.jobSize; }
System.out.printf("\t-- %d job/s in the Job Queue -- \n\n", jobs.size()); } }
public Queue<PCB> CPUScheduler()
{ JobScheduler();
if(jobs.size() > 0)
{ System.out.println("\t-- Filling Ready Queue --\n");
while(jobs.size() > 0 && ramSize > 0)
{ Job j = jobs.poll();
PCB p = new PCB(j.jID, j.ECU, j.jobSize);
p.admit(); // process state = ready
ready.add(p);
hdSize += j.jobSize;
ramSize -= j.jobSize; }
System.out.printf("\t-- %d Process/es are in the Ready Queue -- \n\n", ready.size()); }
return ready; }
public void generateOutput(int normal, int abnormal)
{ File f= new File("Results.txt");
try
{ FileWriter fw = new FileWriter(f);
double avg= 0;
if(n != 0)
avg = total/n;
fw.write("The total number of jobs processed " + (normal + abnormal) + " from a total of " + n + ".\n");
fw.write("The number of jobs that completed normally " + normal + ".\n");
fw.write("The number of jobs that completed abnormally " + abnormal + ".\n");
fw.write("The maximum job size is " + max + "KB. \n");
fw.write("The minimum job size is " + min + "KB. \n");
fw.write("The average job size is " + avg + "KB. \n");
fw.close(); }
catch(Exception e)
{ e.getMessage(); } } }