获取其他线程的回溯 [英] Getting a backtrace of other thread

查看:206
本文介绍了获取其他线程的回溯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中,要获取回溯,可以使用backtrace()库调用,但它仅返回当前线程的回溯.假设我知道它是TID(或pthread_t)并且可以保证它可以入睡,是否有任何方法可以获取其他线程的回溯?

In Linux, to get a backtrace you can use backtrace() library call, but it only returns backtrace of current thread. Is there any way to get a backtrace of some other thread, assuming I know it's TID (or pthread_t) and I can guarantee it sleeps?

似乎libunwind(http://www.nongnu.org/libunwind/)项目可以提供帮助.问题是CentOS不支持它,因此我不希望使用它.

It seems that libunwind (http://www.nongnu.org/libunwind/) project can help. The problem is that it is not supported by CentOS, so I prefer not to use it.

还有其他想法吗? 谢谢.

Any other ideas? Thanks.

推荐答案

借助backtrace进行信号处理可以解决您的目的.

Signal Handling with the help of backtrace can solve your purpose.

我的意思是,如果您具有线程的PID,则可以对该线程发出信号.在处理程序中,您可以使用backtrace.由于处理程序将在该特定线程中执行,因此回溯将有您所需要的输出.

I mean if you have a PID of the Thread, you can raise a signal for that thread. and in the handler you can use the backtrace. since the handler would be executing in that partucular thread, the backtrace there would be the output what you are needed.

这篇关于获取其他线程的回溯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆