Taking a heap dump from console when Java VisualVM and JMX is not available to us.
We will use following tools
Dumping heap requires two steps
1) Obtaining target process id
2) Dumping heap for given pid
First we need to obtain the target process id we would like to dump, here I will show couple ways I like to use.
ps aux | grep 'java' ----- userx 29901 6.7 47.0 25418812 3848276 ? Sl Mar23 85:42 /opt/java/bin/java -Djava.util.logging.config.
Here second column indicates our process id (pid)
Second method that is quite useful to obtain pid for java processes
uxserx@WS4:/opt/java/bin# ./jps -l 4281 sun.tools.jps.Jps 29901 org.apache.catalina.startup.Bootstrap
As we see both methods returned us pid of 29901
Npw to perform the dump we issue our second command
userx@WS4:/opt/java/bin# ./jmap -dump:format=b,file=/tmp/heapdump-001.hprof 29901 Dumping heap to /tmp/heapdump-001.hprof ...