forked from BITOCTA/Process-Scheduling-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoundRobin.java
More file actions
72 lines (55 loc) · 1.63 KB
/
RoundRobin.java
File metadata and controls
72 lines (55 loc) · 1.63 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
package process_scheduling_algorithm;
import java.util.*;
public class RoundRobin
{
static void findWaitingTime(int processes[], int n,
int bt[], float wt[], int quantum)
{
float rem_bt[] = new float[n];
for (int i = 0 ; i < n ; i++)
rem_bt[i] = bt[i];
float t = 0;
while(true)
{
boolean done = true;
for (int i = 0 ; i < n; i++)
{
if (rem_bt[i] > 0)
{
done = false;
if (rem_bt[i] > quantum)
{
t += quantum;
rem_bt[i] -= quantum;
}
else
{
t = t + rem_bt[i];
wt[i] = t - bt[i];
rem_bt[i] = 0;
}
}
}
if (done == true)
break;
}
}
static float findavgTime(int processes[], int n, int bt[],
int quantum)
{
System.out.println("Let's calculate the average waiting time using process_scheduling_algorithm.RoundRobin algorithm");
float wt[] = new float[n], tat[] = new float[n];
float total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt, quantum);
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
}
float k = total_wt/n;
return k;
}
public static void main(String[] args)
{
}
}