Let's say you want to create a heap dump of a running Tomcat JVM. First, you will need to get the PID of the Tomcat application server. On Linux, this can be done using the ps command. In this example, the PID of the JVM is 12345.
~]# ps -ef | grep jvm_name root 12345 . . .
The jmap command, which is included with some, but not all versions of Java, can be used. The which command can be used to determine if the jmap command is in your $PATH.
If jmap is in your $PATH, something like this should be returned.
The jmap command can be used to create a heap dump. jmap is a command line tool included with Java. Following is the basic syntax of the jmap command. The PID of the JVM (12345 in this example) is used to create a heap dump of the running Tomcat JVM. This will create a file named heapdump.hprof in the /tmp directory.
jmap -dump:format=b,file=/tmp/heapdump.hprof 12345
Or you could update the Tomcat application servers setenv.sh file to contain the following JAVA_OPTS.
Once the heapdump file has been created, then you can analyze the heap dump.