Mostly technical stuff with some interesting moments of life

Get PID from Java

No comments
This may not be elegant, but it works !

public static String getPid() throws IOException {
    byte[] bo = new byte[100];
    String[] cmd = {"bash", "-c", "echo $PPID"};
    Process p = Runtime.getRuntime().exec(cmd);
    p.getInputStream().read(bo);
    return new String(bo);
}

No comments :

Post a Comment