@Test public void testGetPIDFromOS() { assertNotNull("getPIDFromOS", PID.getPIDFromOS()); }
static String getPIDFromOS() { String pid; final String[] cmd; File tempFile = null; Process process = null; try { try { if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH) .contains("windows")) { cmd = new String[] { "/bin/sh", "-c", "echo $$ $PPID" }; } else { tempFile = File.createTempFile("getpids", ".exe"); extractGetPid(tempFile); cmd = new String[] { tempFile.getAbsolutePath() }; } process = Runtime.getRuntime().exec(cmd); final String processOutput = InputOutput.pumpToString(process.getInputStream(), Charset.defaultCharset()); final StringTokenizer stok = new StringTokenizer(processOutput); stok.nextToken(); pid = stok.nextToken(); process.waitFor(); } finally { if (process != null) { process.getInputStream().close(); process.getOutputStream().close(); process.getErrorStream().close(); process.destroy(); } if (tempFile != null && !tempFile.delete()) { tempFile.deleteOnExit(); } } } catch (final InterruptedException e) { pid = e.toString(); } catch (final IOException e) { pid = e.toString(); } return pid; }
PID { static String getPIDFromOS() { String pid; final String[] cmd; File tempFile = null; Process process = null; try { try { if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH) .contains("windows")) { cmd = new String[] { "/bin/sh", "-c", "echo $$ $PPID" }; } else { tempFile = File.createTempFile("getpids", ".exe"); extractGetPid(tempFile); cmd = new String[] { tempFile.getAbsolutePath() }; } process = Runtime.getRuntime().exec(cmd); final String processOutput = InputOutput.pumpToString(process.getInputStream(), Charset.defaultCharset()); final StringTokenizer stok = new StringTokenizer(processOutput); stok.nextToken(); pid = stok.nextToken(); process.waitFor(); } finally { if (process != null) { process.getInputStream().close(); process.getOutputStream().close(); process.getErrorStream().close(); process.destroy(); } if (tempFile != null && !tempFile.delete()) { tempFile.deleteOnExit(); } } } catch (final InterruptedException e) { pid = e.toString(); } catch (final IOException e) { pid = e.toString(); } return pid; } }
PID { static String getPIDFromOS() { String pid; final String[] cmd; File tempFile = null; Process process = null; try { try { if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH) .contains("windows")) { cmd = new String[] { "/bin/sh", "-c", "echo $$ $PPID" }; } else { tempFile = File.createTempFile("getpids", ".exe"); extractGetPid(tempFile); cmd = new String[] { tempFile.getAbsolutePath() }; } process = Runtime.getRuntime().exec(cmd); final String processOutput = InputOutput.pumpToString(process.getInputStream(), Charset.defaultCharset()); final StringTokenizer stok = new StringTokenizer(processOutput); stok.nextToken(); pid = stok.nextToken(); process.waitFor(); } finally { if (process != null) { process.getInputStream().close(); process.getOutputStream().close(); process.getErrorStream().close(); process.destroy(); } if (tempFile != null && !tempFile.delete()) { tempFile.deleteOnExit(); } } } catch (final InterruptedException e) { pid = e.toString(); } catch (final IOException e) { pid = e.toString(); } return pid; } private  PID(); }
PID { static String getPIDFromOS() { String pid; final String[] cmd; File tempFile = null; Process process = null; try { try { if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH) .contains("windows")) { cmd = new String[] { "/bin/sh", "-c", "echo $$ $PPID" }; } else { tempFile = File.createTempFile("getpids", ".exe"); extractGetPid(tempFile); cmd = new String[] { tempFile.getAbsolutePath() }; } process = Runtime.getRuntime().exec(cmd); final String processOutput = InputOutput.pumpToString(process.getInputStream(), Charset.defaultCharset()); final StringTokenizer stok = new StringTokenizer(processOutput); stok.nextToken(); pid = stok.nextToken(); process.waitFor(); } finally { if (process != null) { process.getInputStream().close(); process.getOutputStream().close(); process.getErrorStream().close(); process.destroy(); } if (tempFile != null && !tempFile.delete()) { tempFile.deleteOnExit(); } } } catch (final InterruptedException e) { pid = e.toString(); } catch (final IOException e) { pid = e.toString(); } return pid; } private  PID(); static String getPID(); }
PID { static String getPIDFromOS() { String pid; final String[] cmd; File tempFile = null; Process process = null; try { try { if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH) .contains("windows")) { cmd = new String[] { "/bin/sh", "-c", "echo $$ $PPID" }; } else { tempFile = File.createTempFile("getpids", ".exe"); extractGetPid(tempFile); cmd = new String[] { tempFile.getAbsolutePath() }; } process = Runtime.getRuntime().exec(cmd); final String processOutput = InputOutput.pumpToString(process.getInputStream(), Charset.defaultCharset()); final StringTokenizer stok = new StringTokenizer(processOutput); stok.nextToken(); pid = stok.nextToken(); process.waitFor(); } finally { if (process != null) { process.getInputStream().close(); process.getOutputStream().close(); process.getErrorStream().close(); process.destroy(); } if (tempFile != null && !tempFile.delete()) { tempFile.deleteOnExit(); } } } catch (final InterruptedException e) { pid = e.toString(); } catch (final IOException e) { pid = e.toString(); } return pid; } private  PID(); static String getPID();  }