how to take jave heap dump every 30 seconds using kill -3 <pid> command

heap-dump, java, shell

Solution

Have you tried such a simple shell script?

while true
do
  jmap -dump:file=/tmp/java-`date +%s`.hprof PID_OF_JVM
  sleep 30
done

This will create one file pear each snapshot. For thread dump you can use similar script:

while true
do
  jstack PID_OF_JVM > stack-`date +%s`.txt
  sleep 30
done

I guess you can use `kill -3` instead of `jstack`.

Problem

Please help in this, i want to run a shell script where it should take jave heap dump every 30 seconds using kill -3 command. Thanks in advance.

Original source

Related problems