Question

In: Computer Science

IN JAVA Implement SRT scheduling algorithms based on following actions: The simulation maintains the current time,...

IN JAVA

Implement SRT scheduling algorithms based on following actions:

The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions:

repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */
while no process is active, increment t /* if no process is ready to run, just advance t */
choose active processes pᵢ to run next
according to scheduling algorithm /* Ex: FIFO, SJF, SRT */
decrement Rᵢ /* pᵢ has accumulated 1 CPU time unit */
if Rᵢ == 0 /* process i has terminated */
set active flag of pᵢ = 0 /* process i is excluded from further consideration */
TTᵢ = t - Aᵢ /* the turnaround time of process i is the time
since arrival, TTᵢ, until the current time t */
compute the average turnaround time,
ATT, by averaging all values TTᵢ

Solutions

Expert Solution

import java.io.PrintWriter;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class SRTF {
private static class Process {
private final int PID;
private final int submitTime;
private int burst;
private int completeTime;
private boolean dispatched;
  
public Process(int PID, int submitTime, int burst) {
this.PID = PID;
this.submitTime = submitTime;
this.burst = burst;
this.completeTime = -1;
this.dispatched = false;
}
  
public int getPID() {
return this.PID;
}
  
public int getSubmissionTime() {
return this.submitTime;
}
  
public int getBurst() {
return this.burst;
}
  
public void reduceBurst(int q) {
burst -= (int) Math.min(burst, q);
}
  
public void setCompleteTime(int time) {
this.completeTime = time;
}
  
public int getCompleteTime() {
return this.completeTime;
}
  
public boolean isCompleted() {
return this.completeTime != -1;
}
  
public void setDispatched() {
this.dispatched = true;
}
  
public boolean isDispatched() {
return this.dispatched;
}
}
  
private static boolean checkCompleted(Process[] parr) {
for(Process p : parr) {
if(!p.isCompleted()) {
return false;
}
}
return true;
}
  
public static void main(String[] args) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(System.out);
PrintWriter out = new PrintWriter(osw);
  
Process[] parr = new Process[5];
parr[0] = new Process(0, 1, 3);
parr[1] = new Process(1, 2, 1);
parr[2] = new Process(2, 2, 5);
parr[3] = new Process(3, 3, 4);
parr[4] = new Process(4, 4, 2);
  
int clock = 1;
int quantum = 1;
  
while(!checkCompleted(parr)) {
// Detect shortest burst process which
// has not completed
Process minBurstProc = null;
int minBurst = Integer.MAX_VALUE;
  
for(Process p : parr) {
if(!p.isCompleted() && p.getSubmissionTime() <= clock && p.getBurst() < minBurst) {
minBurst = p.getBurst();
minBurstProc = p;
}
}
  
clock += quantum;
  
if(minBurstProc != null) {
minBurstProc.reduceBurst(quantum);
  
if(minBurstProc.getBurst() == 0) {
minBurstProc.setCompleteTime(clock);
}
}
}
  
out.println("PID\tCompletion Time");
  
for(Process p : parr) {
out.print(p.getPID());
out.print("\t");
out.print(p.getCompleteTime());
out.println(" units");
}
  
out.close();
}
}


Related Solutions

IN JAVA Implement SJF scheduling algorithms based on following actions: The simulation maintains the current time,...
IN JAVA Implement SJF scheduling algorithms based on following actions: The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions: repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */ while no process is active, increment t /* if no process is ready to run, just advance t */ choose active processes pᵢ to run...
Implement 3 scheduling algorithms, FIFO, SJF, SRT based on following actions: The simulation maintains the current...
Implement 3 scheduling algorithms, FIFO, SJF, SRT based on following actions: The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions: repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */ while no process is active, increment t /* if no process is ready to run, just advance t */ choose active processes pᵢ to...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in class: 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with different quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 50 requests and service them according to each of the algorithms you chose. The program will be passed the initial position of the disk head as a parameter on the command line and report the total amount of head...
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2....
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with di_erent quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the ready queue The simulator needs to...
Program in java 1- Implement an algorithms to calculate the sum of all numbers in an...
Program in java 1- Implement an algorithms to calculate the sum of all numbers in an array.   2- Implement an algorithm to determine if an array has all unique integer values. 3- Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Example 1: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
Write a program that implements the follow disk scheduling algorithms. You can use C or Java...
Write a program that implements the follow disk scheduling algorithms. You can use C or Java for this assignment. FCFS SSTF SCAN C-SCAN LOOK C-LOOK Your program will service a disk with 5000 cylinders (numbered 0 to 4999). Your program will generate a random initial disk head position, as well as a random series of 1000 cylinder requests, and service them using each of the 6 algorithms listed above. Your program will report the total amount of head movement required...
Project objective: To learn more about OS scheduling through a hands-on simulation programming experience Implement the...
Project objective: To learn more about OS scheduling through a hands-on simulation programming experience Implement the following 3 CPU scheduling algorithms Simulate and evaluate each with the set of eight processes below. Use any programming language. The program listing should be submitted with the report. FCFS non-preemptive (partial results provided) SJF non-preemptive MLFQ Multilevel Feedback Queue (absolute priority in higher queues)             Queue 1 uses RR scheduling with Tq = 5             Queue 2 uses RR scheduling with Tq =...
Write one Java application based on the following directions and algorithms. Make sure the results from...
Write one Java application based on the following directions and algorithms. Make sure the results from each of the bulleted items is separate and easy to read/understand. Create an array that will hold 4 string values. Write three separate statements to store your favorite color, your favorite song, and your favorite restaurant in the array elements. I do not want you to use a loop in this logic; use hard-coded index values instead. Print *ALL FOUR* of the values of...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java program to reverse a stack of characters. Make your own assumption and your own design on the methods signature, inputs, outputs, and the full main program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT