PID of Java Process From Same Process Without Using Exec


/ Published in: Java
Save to your folder(s)

This is especially useful to have appear in logs. While it is totally up to the JVM implementation what to return for the name, most seem to return a numeric process identifier.


Copy this code and paste it in your HTML
  1. String pid = ManagementFactory.getRuntimeMXBean().getName();
  2. log.info("Foo started: pid = " + pid);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.