Ich habe eine Zuordnung zur Implementierung eines spezifischen Prozessplanungsalgorithmus und zur Simulation seines Verhaltens in einer Multiprogrammierungsumgebung. Ziel ist es, die Leistung des Planungsalgorithmus in Bezug auf die CPU -Auslastung, die durchschnittliche Turnaround -Zeit und die durchschnittliche Wartezeit zu demonstrieren. < /P>
import java.util.*;
public class Process {
int id;
int arrivalTime;
int burstTime;
int remainingTime;
int completionTime;
int turnaroundTime;
int waitingTime;
int responseTime = -1;
public Process(int id, int arrivalTime, int burstTime) {
this.id = id;
this.arrivalTime = arrivalTime;
this.burstTime = burstTime;
this.remainingTime = burstTime;
}
}
< /code>
Und dies ist die Hauptstufe: < /p>
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of processes: ");
int n = scanner.nextInt();
List processes = new ArrayList();
for (int i = 0; i < n; i++) {
System.out.print("Enter arrival time and burst time for process P" + (i + 1) + ": ");
int arrival = scanner.nextInt();
int burst = scanner.nextInt();
processes.add(new Process(i + 1, arrival, burst));
}
Scheduler scheduler = new Scheduler(processes);
scheduler.run();
scheduler.printResults();
}
}
< /code>
Es sollte zuerst kürzeste Zeit verwenden (präventive sjf). Zuerst kommen zuerst erster Serve.Number of processes= 4 (P1, P2, P3, P4)
Arrival times and burst times as follows:
P1: Arrival time = 0, Burst time = 8 ms
P2: Arrival time = 1, Burst time = 4 ms
P3: Arrival time = 2, Burst time = 5 ms
P4: Arrival time = 3, Burst time = 5 ms
Scheduling Algorithm: Shortest remaining time first
Context Switch: 1 ms
Time Process/CS
0-1 P1
1-2 CS
2-6 P2
6-7 CS
7-12 P3
12-13 CS
13-18 P4
18-19 CS
19-26 P1
Performance Metrics
Average Turnaround Time: 14
Average Waiting Time: 8.5
CPU Utilization: 84.62
< /code>
Tatsächliche Ausgabe: < /p>
Number of processes= 4 (P1, P2, P3, P4)
Arrival times and burst times as follows:
P1: Arrival time = 0, Burst time = 8 ms
P2: Arrival time = 1, Burst time = 4 ms
P3: Arrival time = 2, Burst time = 5 ms
P4: Arrival time = 3, Burst time = 5 ms
Scheduling Algorithm: Shortest remaining time first
Context Switch: 1 ms
Time Process/CS
0-8 P1
8-9 CS
9-13 P2
13-14 CS
14-19 P3
19-20 CS
20-25 P4
25-26 idle
Performance Metrics
Average Turnaround Time: 14.75
Average Waiting Time: 9.25
CPU Utilization: 88.46%
Ich habe eine Zuordnung zur Implementierung eines spezifischen Prozessplanungsalgorithmus und zur Simulation seines Verhaltens in einer Multiprogrammierungsumgebung. Ziel ist es, die Leistung des Planungsalgorithmus in Bezug auf die CPU -Auslastung, die durchschnittliche Turnaround -Zeit und die durchschnittliche Wartezeit zu demonstrieren. < /P> [code]import java.util.*;
public class Scheduler { private List processes; private int currentTime = 0; private List ganttChart = new ArrayList(); private int contextSwitches = 0; private int totalIdleTime = 0;
public Scheduler(List processes) { this.processes = new ArrayList(processes); this.processes.sort((a, b) -> a.arrivalTime - b.arrivalTime); }
public void run() { List readyQueue = new ArrayList(); int index = 0; Process currentProcess = null;
while (index < processes.size() || !readyQueue.isEmpty() || currentProcess != null) { // Add arriving processes to the ready queue while (index < processes.size() && processes.get(index).arrivalTime 0 && !ganttChart.get(i).equals(ganttChart.get(i - 1))) { System.out.printf("%d-%d %s\n", start, i, ganttChart.get(i - 1)); start = i; } } System.out.printf("%d-%d %s\n\n", start, ganttChart.size(), ganttChart.get(ganttChart.size() - 1));
public class Process { int id; int arrivalTime; int burstTime; int remainingTime; int completionTime; int turnaroundTime; int waitingTime; int responseTime = -1;
public Process(int id, int arrivalTime, int burstTime) { this.id = id; this.arrivalTime = arrivalTime; this.burstTime = burstTime; this.remainingTime = burstTime; } } < /code> Und dies ist die Hauptstufe: < /p> import java.util.*;
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of processes: "); int n = scanner.nextInt(); List processes = new ArrayList();
for (int i = 0; i < n; i++) { System.out.print("Enter arrival time and burst time for process P" + (i + 1) + ": "); int arrival = scanner.nextInt(); int burst = scanner.nextInt(); processes.add(new Process(i + 1, arrival, burst)); }
Scheduler scheduler = new Scheduler(processes); scheduler.run(); scheduler.printResults(); } } < /code> Es sollte zuerst kürzeste Zeit verwenden (präventive sjf). Zuerst kommen zuerst erster Serve.Number of processes= 4 (P1, P2, P3, P4) Arrival times and burst times as follows: P1: Arrival time = 0, Burst time = 8 ms P2: Arrival time = 1, Burst time = 4 ms P3: Arrival time = 2, Burst time = 5 ms P4: Arrival time = 3, Burst time = 5 ms Scheduling Algorithm: Shortest remaining time first Context Switch: 1 ms Time Process/CS 0-1 P1 1-2 CS 2-6 P2 6-7 CS 7-12 P3 12-13 CS 13-18 P4 18-19 CS 19-26 P1 Performance Metrics Average Turnaround Time: 14 Average Waiting Time: 8.5 CPU Utilization: 84.62 < /code> Tatsächliche Ausgabe: < /p> Number of processes= 4 (P1, P2, P3, P4) Arrival times and burst times as follows: P1: Arrival time = 0, Burst time = 8 ms P2: Arrival time = 1, Burst time = 4 ms P3: Arrival time = 2, Burst time = 5 ms P4: Arrival time = 3, Burst time = 5 ms Scheduling Algorithm: Shortest remaining time first Context Switch: 1 ms Time Process/CS 0-8 P1 8-9 CS 9-13 P2 13-14 CS 14-19 P3 19-20 CS 20-25 P4 25-26 idle Performance Metrics Average Turnaround Time: 14.75 Average Waiting Time: 9.25 CPU Utilization: 88.46% [/code] Was ist das Problem?