Sunday, June 26, 2011

PID of Java Process From Same Process Without Using Exec ..!

Yes, we can do it with out doing Exec operation, It is possible thru JMX.
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.


final String pid = ManagementFactory.getRuntimeMXBean().getName();
log.info("Application is started with pid: " + pid);

Cheers,
Varra

No comments:

Post a Comment