Question: import java.io.*; import java.util.ArrayList; public class SRTF2 { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int int for
import java.io.*;
import java.util.ArrayList;
public class SRTF2 {
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int int for
x=100,c=0 ,stop=000,n=0; pid [] = new int[x];
(int j = 0; j < x; j++) { System.out.print("Please enter PID: "); pid[j] = Integer.parseInt(br.readLine()); if (pid[j] == stop) {
break; }
c++; }
n=c;
//System.out.println("Please enter PID: " +n );
int proc[][] = new int[n +1][4];//proc[][0] is the AT array,[][1] - RT,[][2] - WT,[][3] - TAT
for (int i = 1; i <= n; i++) {
System.out.println("");
System.out.print("Please enter the Arrival Time for Process " + i + ": "); proc[i][0] = Integer.parseInt(br.readLine());
System.out.print("Please enter the Burst Time for Process " + i + ": "); proc[i][1] = Integer.parseInt(br.readLine());
}
System.out.println();
System.out.println("The Gantt chart:");
//Calculation of Total Time and Initialization of Time Chart array int total_time = 0;
for(int i = 1; i <= n; i++)
{
total_time += proc[i][1]; }
int time_chart[] = new int[total_time];
for(int i = 0; i < total_time; i++)
{
} }
//Assign selected process to current time in the Chart
time_chart[i] = sel_proc;
//Selection of shortest process which has arrived
int sel_proc = 0;
int min = 99999;
for(int j = 1; j <= n; j++) {
if(proc[j][0] <= i)//Condition to check if Process has arrived {
if(proc[j][1] < min && proc[j][1] != 0) {
min = proc[j][1];
sel_proc = j;
}
//Decrement Remaining Time of selected process by 1 since it has been assigned the CPU for 1 unit of time
proc[sel_proc][1]--;
//WT and TAT Calculation
for(int j = 1; j <= n; j++)
{
if(proc[j][0] <= i) {
if(proc[j][1] != 0) {
proc[j][3]++;//If process has arrived and it has not already its TT is incremented by 1
if(j != sel_proc)//If the process has not been currently assigned the its WT is incremented by 1
proc[j][2]++;
}
else if(j == sel_proc)//This is a special case in which the process has been assigned CPU and has completed its execution
proc[j][3]++;
} }
//Printing the Time Chart
if(i != 0) {
if(sel_proc != time_chart[i - 1])
//If the CPU has been assigned to a different Process we need to print the current value of time and the name of
//the new Process
{
System.out.print("--" + i + "--P" + sel_proc);
} }
else//If the current time is 0 i.e the printing has just started we need to print the name of the First selected Process
System.out.print(i + "--P" + sel_proc);
if(i == total_time - 1)//All the process names have been printed now we have to
print the time at which execution ends
completed execution CPU and has arrived
System.out.print("--" + (i + 1)); System.out.println();
} System.out.println();
//Printing the WT and TAT for each Process
System.out.println("P\t WT \t TAT "); for(int i = 1; i <= n; i++)
{
System.out.printf("%d\t%2dms\t%2dms",i,proc[i][2],proc[i][3]);
System.out.println(); }
System.out.println();
//Printing the average
float WT = 0,TAT = 0; for(int i = 1; i <= n; {
WT += proc[i][2];
TAT += proc[i][3]; }
WT & TAT
i++)
WT /= n;
TAT /= n;
System.out.println("The Average WT is: " + WT + "ms"); System.out.println("The Average TAT is: " + TAT + "ms");
} }
can someone complete the code to calculate the respond time and average of response time?
"operating system course". SRTF scheduling ?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
