Kod:
[CODE]public static String[][] getProcesses() {
try {
Process process;
if(System.getProperty("os.name").toLowerCase().startsWith("windows")) {
process = Runtime.getRuntime().exec("tasklist");
}else{
process = Runtime.getRuntime().exec("ps -e");
}
InputStream inputStream = process.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String tline = "";
String res = tline;
int l = 0;
while ((tline = bufferedReader.readLine()) != null) {
if(l > 2) {
res += tline + System.getProperty("line.separator");
}
l++;
}
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
String[] lines = res.split(System.getProperty("line.separator"));
ArrayList<String[]> values = new ArrayList<String[]>();
for(String line : lines) {
ArrayList<String> vars = new ArrayList<String>(Arrays.asList(line.split("\\s{2,100}")));
String one = vars.get(1);
vars.remove(1);
String[] ones = one.split("\\s{1}");
vars.add(1, ones[1]);
vars.add(1, ones[0]);
values.add(vars.toArray(new String[5]));
}
return values.toArray(new String[values.size()][5]);
} catch (Exception e) {
e.printStackTrace();
}
return null;