能够当所述线程中的一个被切换上下文(即,暂停),以检测可以找到?
至于你的问题是否可能 - 它认为这是可能的。至少SystemTap(https://sourceware.org/systemtap/)可以做到这一点。
probe scheduler.ctxswitch
{
if (target_pid != 0
&& next_pid != target_pid
&& prev_pid != target_pid)
next
if (target_name != ""
&& prev_task_name != target_name
&& next_task_name != target_name)
next
printf("%-16s%5d %5d %5d:%5d:%s ==> %5d:%5d:%s %-16s\n",prev_task_name,
task_cpu(prev_task),gettimeofday_ns(),prev_pid,prev_priority,state_calc(prevtsk_state),next_pid,
next_priority,state_calc(nexttsk_state),next_task_name)
}
据我知道的SystemTap编译STP文件,把那么在Linux内核,并显示您的信息。
我不知道如何在用户空间和C++程序中获取这些信息。但它似乎也有可能(http://netsplit.com/tracing-on-linux):
其他跟踪事件可用于用户空间!我们并不需要 写内核模块可以挂接到他们,但显然我们 只能读取数据这样
因此,这将是巨大的,如果你能发现它,稍后回答自己题。