Linux – the difference between /proc/self/stack and output from pstack

debuggingkernellinux-kernelmonitoringproc

I have been looking through the documentation for /proc and the "stack" object being a new'ish object in proc, I have also looked through the kernel commit to create it — however the documentation does not detail exactly what is in the /proc/self/stack file — and since I intuitively expected it to be the actual stack of the process — however the old pstack tool gives a different (and more believable) output.

So as an example of the stack for bash

$ cat /proc/self/stack 
[<ffffffff8106f955>] do_wait+0x1c5/0x250
[<ffffffff8106fa83>] sys_wait4+0xa3/0x100
[<ffffffff81013172>] system_call_fastpath+0x16/0x1b
[<ffffffffffffffff>] 0xffffffffffffffff

and, using pstack

$ pstack $$
#0  0x00000038cfaa664e in waitpid () from /lib64/libc.so.6
#1  0x000000000043ed42 in ?? ()
#2  0x000000000043ffbf in wait_for ()
#3  0x0000000000430bc9 in execute_command_internal ()
#4  0x0000000000430dbe in execute_command ()
#5  0x000000000041d526 in reader_loop ()
#6  0x000000000041ccde in main ()

The addresses are different, and obviously the symbols are not at all the same….

Does anybody have an explanation for the difference and/or a document which describes what is actually shown in /proc-stack?

Best Answer

The file /proc/$pid/stacks shows kernel stacks. On your system, memory addresses of the form ffffffff8xxxxxxx are in the space that's reserved for the kernel. There's not much documentation, you can check the source code. In contracst, the pstack program shows user-space stacks (using its knowledge of executable formats).

Related Question