List of usage examples for java.lang Runtime getRuntime
public static Runtime getRuntime()
From source file:edu.berkeley.sparrow.daemon.util.Resources.java
public static int getSystemMemoryMb(Configuration conf) { int systemMemory = -1; try {// w w w .j av a 2 s . com Process p = Runtime.getRuntime().exec("cat /proc/meminfo"); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = in.readLine(); while (line != null) { if (line.contains("MemTotal")) { String[] parts = line.split("\\s+"); if (parts.length > 1) { int memory = Integer.parseInt(parts[1]) / 1000; systemMemory = memory; } } line = in.readLine(); } } catch (IOException e) { } if (conf.containsKey(SparrowConf.SYSTEM_MEMORY)) { return conf.getInt(SparrowConf.SYSTEM_MEMORY); } else { if (systemMemory != -1) { return systemMemory; } else { return SparrowConf.DEFAULT_SYSTEM_MEMORY; } } }
From source file:Main.java
/** * Check that console output contains the specified text * * @param command Console command/*from ww w. ja v a 2s.c o m*/ * @param outputLine Text to check for * @return True if the output line was found in the logs from the given * command, false otherwise. */ public static boolean checkConsole(String command, String outputLine) throws Exception { boolean stringFound = false; Process process = Runtime.getRuntime().exec(command); String line; BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); while ((line = bufferedReader.readLine()) != null) { if (line.contains(outputLine)) { stringFound = true; break; } } return stringFound; }
From source file:Main.java
private static void initProcess() { if (process == null) try {// w w w. ja v a 2 s. c o m process = Runtime.getRuntime().exec("su"); } catch (Exception e) { e.printStackTrace(); } }
From source file:SystemKit.java
/** * @return total memory available by the VM in kilobytes. * * @author Klaus Meffert//from w ww . ja v a 2 s .c o m * @since 3.2.1 */ public static double getTotalMemoryKB() { return (Runtime.getRuntime().totalMemory() / 1024); }
From source file:Main.java
public static List<String> getSDCardPaths() { List<String> list = new ArrayList<String>(); BufferedReader br = null;/*from w ww . j a va2 s .co m*/ try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("mount"); InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); String line; br = new BufferedReader(isr); while ((line = br.readLine()) != null) { if (line.contains("secure")) continue; if (line.contains("asec")) continue; if (line.contains("fat")) { String columns[] = line.split(" "); if (columns != null && columns.length > 1) { list.add(columns[1]); } } else if (line.contains("fuse")) { String columns[] = line.split(" "); if (columns != null && columns.length > 1) { list.add(columns[1]); } } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { } } } return list; }
From source file:Main.java
public static int findProcessIdWithPidOf(String command) throws Exception { int procId = -1; Runtime r = Runtime.getRuntime(); Process procPs = null;//ww w. ja v a 2 s . c o m String baseName = new File(command).getName(); // fix contributed my mikos on 2010.12.10 procPs = r.exec(new String[] { SHELL_CMD_PIDOF, baseName }); // procPs = r.exec(SHELL_CMD_PIDOF); BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { try { // this line should just be the process id procId = Integer.parseInt(line.trim()); break; } catch (NumberFormatException e) { Log.e("TorServiceUtils", "unable to parse process pid: " + line, e); } } return procId; }
From source file:Main.java
/** * * @return */ public static int getNbCpus() { return Runtime.getRuntime().availableProcessors(); }
From source file:Main.java
public static void killProcesses(Context context, int pid, String processName) { String cmd = "kill -9 " + pid; String Command = "am force-stop " + processName + "\n"; Process sh = null;/*from w w w.ja v a 2 s. c o m*/ DataOutputStream os = null; try { sh = Runtime.getRuntime().exec("su"); os = new DataOutputStream(sh.getOutputStream()); os.writeBytes(Command + "\n"); os.writeBytes(cmd + "\n"); os.writeBytes("exit\n"); os.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { sh.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // AbLogUtil.d(AbAppUtil.class, "#kill -9 "+pid); // L.i(processName); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); String packageName = null; try { if (processName.indexOf(":") == -1) { packageName = processName; } else { packageName = processName.split(":")[0]; } activityManager.killBackgroundProcesses(packageName); // Method forceStopPackage = activityManager.getClass().getDeclaredMethod("forceStopPackage", String.class); forceStopPackage.setAccessible(true); forceStopPackage.invoke(activityManager, packageName); } catch (Exception e) { e.printStackTrace(); } }
From source file:ch.epfl.eagle.daemon.util.Resources.java
public static int getSystemMemoryMb(Configuration conf) { int systemMemory = -1; try {// ww w . java 2s . c o m Process p = Runtime.getRuntime().exec("cat /proc/meminfo"); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = in.readLine(); while (line != null) { if (line.contains("MemTotal")) { String[] parts = line.split("\\s+"); if (parts.length > 1) { int memory = Integer.parseInt(parts[1]) / 1000; systemMemory = memory; } } line = in.readLine(); } } catch (IOException e) { } if (conf.containsKey(EagleConf.SYSTEM_MEMORY)) { return conf.getInt(EagleConf.SYSTEM_MEMORY); } else { if (systemMemory != -1) { return systemMemory; } else { return EagleConf.DEFAULT_SYSTEM_MEMORY; } } }
From source file:Main.java
private static String getSystemProperty() { String line = ""; BufferedReader input = null;//from w w w .jav a 2 s . c o m try { Process p = Runtime.getRuntime().exec("getprop"); input = new BufferedReader(new InputStreamReader(p.getInputStream()), 2048); String ret = input.readLine(); while (ret != null) { line += ret + "\n"; ret = input.readLine(); } input.close(); } catch (IOException ex) { Log.e(TAG, "Unable to read sysprop", ex); return null; } finally { if (input != null) { try { input.close(); } catch (IOException e) { Log.e(TAG, "Exception while closing InputStream", e); } } } return line; }