Find the answer to your Linux question:
Results 1 to 7 of 7
Hi, Is there any way to print the user stack of the thread which is getting killed ? What i\I want to do is following: 1. Send a Kill signal ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    3

    printing call stack of user thread


    Hi,

    Is there any way to print the user stack of the thread which is getting killed ? What i\I want to do is following:

    1. Send a Kill signal to a thread running in user space
    2. Catch the signal in kernel in signal.c and print the call stack of the thread (not the signal stack ).

    My intention is to see what the user thread was doing when it received the signal.

    If anyone can help, please let me know. Thanks in advance

  2. #2
    Just Joined!
    Join Date
    Jul 2009
    Posts
    49

    Getting a call stack...

    You can always compile your app with the -g option so that you have gdb symbols available in your application. You then just run the app under gdb and wait for it to die (or send the signal yourself). Then just dump the stack I can't remember the actual command but if you muck about in the help inside gdb, I think it's something like trace.

    You will then get the call stack down through the application and into the library etc...

    I don't think you need to bother the kernel with this at all.

    Hope this helps...

    Cheers!!

  3. #3
    Just Joined!
    Join Date
    May 2010
    Posts
    3
    Thanks for your reply. Actually I cannot use gdb for some reason. So is there any way programatically to dump the call stack ?

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jul 2009
    Posts
    49

    you could try to ...

    find out how gdb dumps the call stack and build it into your code so it gets dumped when the app or thread terminates. I'm sure a search for call tracing would yield you some results. If your thread is a "pthread" then there is a way of configuring them to automatically call a series of functions when the thread is terminated. One of these of functions could be to dump the call stack.

    This is handled in user space though so a kernel solution would not be a good fit. The kernel would only really know about what app got what signal and some resources it has (that have to be released with it sees that the app was killed or terminated). The apps call stack is beyond it's perview.

    I have to ask, why can't you use gdb?

    Cheers!!

  6. #5
    Just Joined!
    Join Date
    Apr 2009
    Posts
    2

    pstack to print process stak

    You can use following command in your code to print stack trace of process

    system("pstack <pid>");

    You can create string pstack <pid>.
    for getting pid of current process used getpid system call.

  7. #6
    Just Joined!
    Join Date
    May 2010
    Posts
    3
    Hi,
    Actualluy I am trying this on Android and I had tried gdb on the platform but without much success because of its bionic C library.

  8. #7
    Just Joined!
    Join Date
    Apr 2009
    Posts
    2
    You can download the code for lsstack from sourceforge.net to see how to access stack of a running process

Posting Permissions

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