Alex Rivera | Logout

How to get a thread and heap dump of a Java process on Windows that's not running in a console

Asked 2009-01-02T18:17:31.117
285

I have a Java application that I run from a console which in turn executes an another Java process. I want to get a thread/heap dump of that child process.

On Unix, I could do a kill -3 <pid> but on Windows AFAIK the only way to get a thread dump is Ctrl-Break in the console. But that only gives me the dump of the parent process, not the child.

Is there another way to get that heap dump?

Edit
Report

2 Answers

482

You can use jmap to get a dump of any process running, assuming you know the pid.

Use Task Manager or Resource Monitor to get the pid. Then

jmap -dump:format=b,file=heap.hprof <pid>

to get the heap for that process.

For systems where bash and pgrep are installed and a single Java process is running, try:

jmap -dump:format=b,file=heap.hprof $(pgrep java)
answered 2010-06-15T04:12:24.430
10

You can send the kill -3 <pid> from Cygwin. You have to use the Cygwin ps options to find windows processes then just send the signal to that process.

answered 2009-01-02T18:19:51.907

Your Answer