List of usage examples for java.lang Runtime getRuntime
public static Runtime getRuntime()
From source file:Main.java
public static void runtimeGC() { Runtime.getRuntime().gc(); }
From source file:Main.java
public static long getUsedMemorySize() { long freeSize = 0L; long totalSize = 0L; long usedSize = -1L; try {//from www . j a va 2 s. c o m Runtime info = Runtime.getRuntime(); freeSize = info.freeMemory(); totalSize = info.totalMemory(); usedSize = totalSize - freeSize; } catch (Exception e) { e.printStackTrace(); } return usedSize; }
From source file:Main.java
public static long getUsedMemorySize() { long freeSize = 0L; long totalSize = 0L; long usedSize = -1L; try {/*w w w .j a v a 2 s .c o m*/ Runtime info = Runtime.getRuntime(); freeSize = info.freeMemory(); totalSize = info.totalMemory(); usedSize = totalSize - freeSize; } catch (Exception e) { e.printStackTrace(); } return usedSize / 1048576L; }
From source file:Main.java
public static void runAsRoot(String[] commands) throws IOException, InterruptedException { Process p = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); for (String cmd : commands) { os.writeBytes(cmd + "\n"); }// w w w .jav a 2 s. c om os.writeBytes("exit\n"); os.flush(); os.close(); p.waitFor(); }
From source file:Main.java
public static void killProcess(int pid) { Process sh = null;/*from w w w .j a va 2 s . co m*/ DataOutputStream os = null; try { sh = Runtime.getRuntime().exec("su"); os = new DataOutputStream(sh.getOutputStream()); final String Command = "kill -9 " + pid + "\n"; os.writeBytes(Command); os.flush(); sh.waitFor(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void clearResource(String targetDir) { String[] str = { "rm", "-r", targetDir }; try {/*from w ww . j av a2s . co m*/ Process ps = Runtime.getRuntime().exec(str); try { ps.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static long getPhysicalMemorySize() { long freeSize = 0L; long totalSize = 0L; long usedSize = -1L; try {/*from w w w .ja v a 2s. c o m*/ Runtime info = Runtime.getRuntime(); freeSize = info.freeMemory(); totalSize = info.totalMemory(); usedSize = totalSize - freeSize; } catch (Exception e) { e.printStackTrace(); } return totalSize / 1048576L; }
From source file:Main.java
public static void forceStopAPK(String pkgName) { Process sh = null;/*from w w w. java 2s . c o m*/ DataOutputStream os = null; try { sh = Runtime.getRuntime().exec("su"); os = new DataOutputStream(sh.getOutputStream()); final String Command = "am force-stop" + pkgName; os.writeBytes(Command); os.flush(); sh.waitFor(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
private static boolean checkRootMethod3() { Process process = null;//from w w w .ja v a 2 s .c o m try { process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" }); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); if (in.readLine() != null) return true; return false; } catch (Throwable t) { return false; } finally { if (process != null) process.destroy(); } }
From source file:Main.java
public static String dumpFile(String filename) { String line = ""; try {/*from www . j a v a2 s . c o m*/ Process ifc = Runtime.getRuntime().exec("cat " + filename); BufferedReader bis = new BufferedReader(new InputStreamReader(ifc.getInputStream())); line = bis.readLine(); ifc.destroy(); } catch (java.io.IOException e) { return new String(""); } return line; }