JavaApp extends Process { public long pid() { if(process.getClass().getName().equals("java.lang.UNIXProcess")) { return ((Integer) Reflection.get("pid", process)).longValue(); } else { throw new UnsupportedOperationException( "Cannot retrieve the pid on the underlying platform"); } } JavaApp(String source);  JavaApp(String classpath, String source, ArrayList<String> options);  JavaApp(String classpath, String source, String... options); void compile(); @Override void destroy(); @Override int exitValue(); @Override InputStream getErrorStream(); @Override InputStream getInputStream(); @Override OutputStream getOutputStream(); boolean isRunning(); void onPrematureShutdown(final PrematureShutdownHandler handler); long pid(); void run(); boolean tryCompile(); @Override int waitFor(); static final String CLASSPATH_SEPARATOR; }
@Test @Ignore public void testPid() { if(Platform.isLinux() || Platform.isMacOsX() || Platform.isSolaris()) { String id = UUID.randomUUID().toString(); JavaApp app = new JavaApp(System.getProperty("java.class.path"), GOOD_SOURCE, "-Dcom.cinchapi.concourse.server.io.process.pid=" + id); app.run(); ProcessBuilder pb = Processes .getBuilderWithPipeSupport("ps aux | grep " + id + " | grep -v \"grep\" | awk '{print $2}' "); try { Process process = pb.start(); ProcessResult result = Processes .waitForSuccessfulCompletion(process); long expected = Long.parseLong(result.out().get(0)); Assert.assertEquals(expected, app.pid()); } catch (IOException e) { throw CheckedExceptions.throwAsRuntimeException(e); } } else { Assert.assertTrue(true); } }