print all threads stack trace of a process in c/c++ on linux platform

Viewed 3172

What I want is to get stacktrace of all threads for running process using c/c++.

The different ways which I know to get stacktrace :

  1. we have backtrace() api but problem with this is that it only gives stacktrace of current thread. Does any one know how to associate it with each running thread?

  2. Second way I tried is using pstack command. pstack takes input as pid of running process shows all stack of all threads. But problem with this is that it is not a C/C++ api so we can't use it in our code. (When I study) pstack is a shell file which in turn used gdb's bt command.

Does anyone know different ways which will help me to get stacktrace of all threads for running process?

1 Answers
Related