Re:Using /proc to get a process' current stack trace
by scottlamb on Monday October 15, 2018 @06:26PM
(#18224467)
> If you are running java instead of a c program the proc stacktrace shows you just the virtual machine state.
No, this is a _kernel_ backtrace: what is happening in kernelspace on behalf of your process. If the work is being done in userspace (that is, in state R; the thread isn't in a syscall or page fault handler), you'll see essentially nothing here. I just tried it on a userspace busylooper and got this:
[<0000000000000000>] exit_to_usermode_loop+0x57/0xb0
[<0000000000000000>] prepare_exit_to_usermode+0x20/0x30
[<0000000000000000>] 0xfffffffffffffff
Java, Python, C++ nothings all look pretty similar.If you want a userspace stack trace, you need a different tool. If you're using an interpreted (or perhaps JITted) language, yes, you probably want something language-specific.
Also note the current stack trace is a per-thread concept, not a per-process one. If you're looking at a multithreaded program, you want to target the thread(s) of interest with "/proc/<PID>/task/<TID>/stack".
Re:Using /proc to get a process' current stack trace
by benfrederickson on Monday October 15, 2018 @12:15PM
(#18220975)
I wrote something that will get you the python interpreter stack from any running cpython process : https://github.com/benfred/py-spy/ , and rbspy can do the same for ruby https://github.com/rbspy/rbspy
Re:Using /proc to get a process' current stack trace
by monocasa on Monday October 15, 2018 @11:10AM
(#18220338)
This is about the kernel's stack trace during a system call, not the user space stack trace.
Re:Using /proc to get a process' current stack trace
by scott_s on Monday October 15, 2018 @11:22AM
(#18220438)
Yes, and if you want to know the user space stack, you may be able to attach gdb to the process: https://stackoverflow.com/questions/2308653/can-i-use-gdb-to...
How about other languages? Python, ruby?
[1] https://stackoverflow.com/questions/4876274/kill-3-to-get-ja...