Is there a way to get the file path/file name of the .so that is currently under execution by a thread? The program is written in c++ and run on a 64-bit Linux 3.0 machine.
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
I think the closes thing is to get a list of all shared libraries loaded by your process. You can do that either by using
pmap
orlsof
.You can sequentially read (from inside your process) the file
/proc/self/maps
to get the memory mapping (including those for shared objects) of the current process.Then you could get your program counter (or those of the caller) and find in which segment it is. Perhaps
backtrace
or GCC builtin_return_address is relevant.You might also use the
dladdr
function.See proc(5), backtrace(3), dladdr(3) man pages, and also this answer.
addenda
From a signal handler you could get the program counter when the signal was sent by using sigaction(2) with
SA_SIGINFO
. Thesa_sigaction
function pointers gets aucontext_t
from which you could get the program counter register (using machine dependent C code). Then you could handle it.I suggest looking into detail into what GCC is doing