How to Obtain a Thread Dump (Stack Traces) from a Java Process or from a Core File of a Java Process on macOS
Applies To
Java SE JDK and JRE - Version 7 to 8
Apple Mac OS X (Intel) (64-bit)
Introduction
On Mac OS X, there are multiple ways to obtain a Thread Dump (a Stack Trace for each thread) from a Java process, or from a core file of a Java process.
Notes:
- This doc applies to the Oracle JDK only, it does not apply to Apple’s JDK.
- This doc applies to Mac OS X. Commands listed here don’t imply that they exist on Mac OS X only.
| Tool | Works on a Process? | Works on a core file? | Java Frames?* | Native Frames?** |
|---|---|---|---|---|
| jstack | yes | yes | yes | no, not available on Darwin |
| jcmd | yes | no | yes | no |
| kill -QUIT, kill -3 | yes | no | yes | no |
| Ctrl + \ | yes | no | yes | no |
| jconsole | yes | no | yes | no |
| jvisualm | yes | no | yes | no |
| ldb | yes | no | no | yes |
*‘Java Frames’ means that the tool is able to print a Java method name
on the stack.
**‘Native Frames’ means that the tool is able to print symbolic or
clear text name of a native function on the stack.
jstack
On Mac OS X, jstack has been available since JDK 7. It is not
available in the Java Runtime Environment (JRE).
The jstack command prints the stack traces of all Java threads in a
given Java process or core file. The -m option, which prints a
mixed-mode stack so that you can see native frames in addition to the
Java frames, does not work on Mac OS X.
jstack [option] pid
jstack [option] executable core
jstack [option] [server-id@]remote-hostname-or-IP
For more information on jstack, see the the documentation for your
version:
- JDK 25 Tools Specification
- JDK 21 Tools Specification
- JDK 17 Tools Specification
- JDK 11 Tools Reference Guide
- JDK 8 Tools and Utilities
jcmd
On Mac OS X, jcmd has been available since JDK 7u4. It is not
available in the JRE.
The jcmd command can print the stack traces of all Java threads in a
given Java process. The -l option will print also
java.util.concurrent locks.
jcmd <pid> Thread.print [-l]
For more information on jcmd, see the documentation for your version:
- JDK 25 Tools Specification
- JDK 21 Tools Specification
- JDK 17 Tools Specification
- JDK 11 Tools Reference Guide
- JDK 8 Tools and Utilities
## kill -QUIT, kill -3
The /bin/kill command is available on Mac OS X.
You can send a SIGQUIT signal to the target process. In that case, the
target process prints a thread dump to its standard output. The kill
command allows you to specify the signal as a name without the SIG
prefix:
kill -QUIT pid
… or as a number (the value for the SIGQUIT signal is 3):
kill -3 pid
Make sure that you know where the log file is if standard output has been redirected.
Ctrl+\
On Mac OS X, the combination of pressing the Ctrl key and the backslash () key at the application console (standard input) causes the Java HotSpot VM to print a thread dump to the application’s standard output. If you don’t find a backslash on your keyboard, you can use the alt+shift+7 key, so ctrl+alt+shift+7 will cause a thread dump.
JConsole
On Mac OS X, the JConsole has been available since JDK 7. It is not available in the JRE. Note that the program is called JConsole, and that the Java Console is something different.
JConsole provides a graphical user interface and its purpose is to monitor a running Java process. In order to obtain a stack trace, connect JConsole to the process and click on the Threads tab. The Threads list in the lower left corner lists all Java threads. Click on the name of a thread in the Threads list to display the stack trace about that thread to the right.
For more information about jconsole, see the documentation for your
version:
- JDK 25 Tools Specification
- JDK 21 Tools Specification
- JDK 17 Tools Specification
- JDK 11 Tools Reference Guide
- JDK 8 Tools and Utilities
Java VisualVM (jvisualvm)
For Mac OS X, jvisualvm was first bundled with the Java SE platform in JDK 7u4. It is not available in the JRE. Similar to jconsole, jvisualvm provides a graphical user interface.
In order to obtain a stack trace, connect jvisualvm to the process and click on the Threads Tab. The Threads list lists all Java threads. Click on the Thread Dump button in order to obtain a thread dump.
See Also
lldb
On Mac OS X 10.9.x, lldb can be used to debug the Java HotSpot VM.
lldb is the command line interface for the LLDB debugger library. It
can obtain stack traces from a live process. lldb is not available by
default. It is part of the Command Line Developer Tools (XCode). If you
are familiar with gdb, you might find the LLDB to GDB command
map to be useful.
In order to avoid privilege problems, it helps to run lldb with root
privileges.
sudo lldb -p pid
Once attached successfully, you can work with the lldb commands. The
prompt is set to (lldb):
(lldb)
In order to get a list of the threads, enter:
(lldb) thread list
An asterisk ’*’ to the left of the lldb thread number indicates the
current thread. You can select a thread by typing “thread select”
followed by the thread id:
(lldb) thread select 1
In order to get a stack trace of the current thread (in the example it
is thread #1), just enter thread backtrace:
(lldb) thread backtrace
In order to get stack traces for all threads, you can enter
thread backtrace all:
(lldb) thread backtrace all
You can execute lldb in non-interactive mode as well (replace <PID> with the actual process id):
echo "attach -p <pid>" > commands
echo "thread backtrace all" >> commands
lldb -s commands` Last reviewed on Sat Feb 01 2025 00:00:00 GMT+0000 (Coordinated Universal Time)