This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
and then examine the resulting line. The last thing on the line is the full command used to start the program and include -Xmx etc if they were specified.
You might need to use the grep '-e' switch to specify a regular expression to more tightly control the matched lines but I leave that up to you.
If you don't actually know the PID then you can grep for the program jar name or class name instead (depends how you invoked it). Of course this will assume that you only have one copy running whereas specifying the PID and using a regex one can exactly match the program of interest.
You can go even further with the 'ps' command and extract just the fields of interest using the --format option. I can never remember the details so consult the 'man' page for 'ps' .
Edit : The information you need to work with can probably be obtained using
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Joined: Jul 18, 2010
Thanks for yr inputs, however I am still wanting to know how can we get the default -Xmxof a running JVM PID which does not have -Xmx set explicitly.
You can use java.lang.Runtime.maxMemory() which will return max memory size that is set using -Xmx.
Oracle Java 5 documentation says that based on your hardware architecture java determines whether it's server configuration or client configuration and then it has some rules to set -Xmx and -Xms
Rohan Dhapodkar wrote:You can use java.lang.Runtime.maxMemory() which will return max memory size that is set using -Xmx.l
It is my understanding that the OP only has the PID of the Java process so cannot get at any of the internal information. This is why I suggested parsing the output of the 'ps' command but obviously this fails if no -Xmx has been set.
One possibility is that if parsing the output of 'ps' does not produce a -Xmx value then the OP should assume the default value which must be documented somewhere. Of course this will only work if there is no way to set the -Xmx other than as an argument to 'java'.