Is there a way to print stacktrace of all threads without attaching GDB?
Or is there a command which I can use as gdb batch mode to print stacktrace of all threads?
The following script works for me on linux Please note that it first finds out the directory of the executable and changes to that directory (because executable can have shared libraries with relative path by using -Wl,-rpath,$dir specified during linking, and you would like gdb to find the symbols for these shared libraries for the stack trace). It also assumes that gdb is present on the system.
#!/bin/bash
pid=$1
EXE=`readlink -f /proc/$pid/exe`
DIR=`dirname $EXE`
cd $DIR
gdb $EXE --batch -ex "attach $pid" -ex "thread apply all bt"