Can I get call stack information for the specified process?

Source: Internet
Author: User

We know that calling BackTrace () can get the call stack information for the current process, and if there is a way to get the call stack information for another process (which we certainly know about the PID of this process).

On the StackOverflow, someone raised the question, the answer is to send a signal to the process, and then by the process in the signal processing function to get its own call stack, and then send back .... Regardless of whether this method works or does not work, it is at least unsuitable for the general situation because it requires signal processing in the specified process.

Think about the GDB tool, GDB can almost attach to any process and get its current call stack information without any additional work done, so to get back to the problem, it is possible to get the call stack information for the specified process, and there is exactly one particular tool Pstack:

1 2 3 4 5 6 7 8 9 10 11-12 [root@localhost ~]# pstack 4468 thread 2 (thread 0x4166f940 (LWP 4469)): #0 0x00007fbcaf6e6b99 in pthread_cond_wait@ @GLIB c_2.3.2 () #1 0x00007fbcb071e9fb in?? () From/proc/4468/exe #2 0x00007fbcaf6e24a7 in Start_thread () from/lib64/libpthread.so.0 #3 0x00007fbcaf9cac2d in CLO NE () from/lib64/libc.so.6 thread 1 (thread 0x7fbcb06f46e0 (LWP 4468): #0 0x00007fbcaf9cb018 in epoll_wait () from/lib 64/libc.so.6 #1 0x00007fbcb072800c in?? () From/proc/4468/exe #2 0x00007fbcb0726fec in?? () From/proc/4468/exe #3 0x00007fbcb071d319 in Main () From/proc/4468/exe [Root@localhost ~]#

As you can see from the previous instance, Pstack can get all the thread call stack information for the specified process (through the process ID). In fact, Pstack is a shell script that is implemented using GDB:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21-22

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.