Skip to content

Instantly share code, notes, and snippets.

@tkfx
Created July 28, 2017 00:48
Show Gist options
  • Select an option

  • Save tkfx/f591f58c18e462ff3e6adb0147331abd to your computer and use it in GitHub Desktop.

Select an option

Save tkfx/f591f58c18e462ff3e6adb0147331abd to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws Exception {
Process proc = Runtime.getRuntime().exec(new String[] {
"/bin/sh",
"-c",
"echo $PPID"
});
if (proc.waitFor() == 0) {
InputStream in = proc.getInputStream();
int available = in.available();
byte[] outputBytes = new byte[available];
in.read(outputBytes);
String pid = new String(outputBytes);
System.out.println("Your pid is " + pid);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment