Find the answer to your Linux question:
Results 1 to 4 of 4
Hi All, What I want is to get stacktrace of all threads for running process periodicaly. The different ways which I know to get stacktrace : 1. we have backtrace() ...
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Posts
    9

    Question Ways to get stack trace of Linux process.

    Hi All,

    What I want is to get stacktrace of all threads for running process periodicaly.

    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 way or more inputs which will help me to get stacktrace of all threads for running process?


    Please let us know your thoughs.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    What about the ptrace() function?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jan 2010
    Posts
    9
    Thanks for your reply

    Yes, ptrace is there, if we use ptrace in our code we need to create anthor process as parent process or we need create a process and attached to our process.

    we want our prcess trace itself. one of our thread periodically invoke and get stack trace of all running threads. Atually I want to avoid another process creation.

    I am not sure is it possible using ptrace ?

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So, although my ptrace manpage doesn't say so, I do believe that ptrace can trace individual threads, not only full processes. I believe that this is does by using the thread ID instead of a PID in the ptrace command. Play with that and see if it works.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...