RoundRobin
For OS project- Nashrahunknown
java
4 years ago
4.8 kB
5
Indexable
// Java program to implement Round Robin // Scheduling with different arrival time class RoundRobin { public static void RoundRobin(int[][] values) { int res = 0; int resc = 0; // for sequence storage String seq = new String(); // copy the burst array and arrival array // for not effecting the actual array int res_b[] = new int[values.length]; int res_a[] = new int[values.length]; for (int i = 0; i < res_b.length; i++) { res_b[i] = values[i][1]; res_a[i] = values[i][2]; } // critical time of system int t = 0; // for store the waiting time int w[] = new int[values.length]; // for store the Completion time int comp[] = new int[values.length]; while (true) { boolean flag = true; for (int i = 0; i < values.length; i++) { // these condition for if // arrival is not on zero // check that if there come before qtime if (res_a[i] <= t) { if (res_a[i] <= values[i][3]) { if (res_b[i] > 0) { flag = false; if (res_b[i] > values[i][3]) { // make decrease the b time t = t + values[i][3]; res_b[i] = res_b[i] - values[i][3] ; res_a[i] = res_a[i] + values[i][3]; } else { // for last time t = t + res_b[i]; // store comp time comp[i] = t - values[i][2]; // store wait time w[i] = t - values[i][1] - values[i][2]; res_b[i] = 0; } } } else if (res_a[i] > values[i][3]) { // is any have less arrival time // the coming process then execute them for (int j = 0; j < values.length; j++) { // compare if (res_a[j] < res_a[i]) { if (res_b[j] > 0) { flag = false; if (res_b[j] > values[i][3]) { t = t + values[i][3]; res_b[j] = res_b[j] - values[i][3]; res_a[j] = res_a[j] + values[i][3]; } else { t = t + res_b[j]; comp[j] = t - values[j][2]; w[j] = t - values[j][1] - values[j][2]; res_b[j] = 0; } } } } if (res_b[i] > 0) { flag = false; if (res_b[i] > values[i][3]) { t = t + values[i][3]; res_b[i] = res_b[i] - values[i][3]; res_a[i] = res_a[i] + values[i][3]; } else { t = t + res_b[i]; comp[i] = t - values[i][2]; w[i] = t - values[i][1] - values[i][2]; res_b[i] = 0; } } } } // if no process is come on thse critical else if (res_a[i] > t) { t++; i--; } } // for exit the while loop if (flag) { break; } } } }
Editor is loading...