How does the pstack command work?

I'm curious to know how the pstack command prints a stack trace of all threads running under PID?

It should be something other than the gdb method, since the process runs inside the gdb environment, but pstack runs after the process has completed.

+3
source share
1 answer

This is the same general idea as gdb. pstack uses ptrace, which allows an external process to join the known pid and print information (the stack is known through the current registers).

If you want to know exactly how to do this, find information on ptrace.

, " gdb". gdb , gdb executable pid.

+3

Source: https://habr.com/ru/post/1753500/


All Articles