c - setitimer 的 ITIMER_PROF(SIGPROF) 是否发送到多线程和 NPTL 以及 Linux(2.6.21.7) 中的每个线程?

标签 c linux pthreads

手册说 setitimer 在整个 PROCESS 中共享,SIGPROF 发送到 PROCESS 而不是线程。

但是当我在我的多线程进程中创建计时器时,除非我为进程中的每个线程创建独立的堆栈来处理信号,否则我将在信号处理程序中遇到一些非常严重的错误。通过一些调试,我确认堆栈(sole stack case)一定已经重新进入了。

所以现在我怀疑 SIGPROF 可能会同时发送到多线程?谢谢!

最佳答案

我不了解你问题的细节,但一般情况是:

A signal may be generated (and thus pending) for a process as a whole (e.g., when sent using kill(2)) or for a specific thread (e.g., certain signals, such as SIGSEGV and SIGFPE, generated as a consequence of executing a specific machine-language instruction are thread directed, as are signals targeted at a specific thread using pthread_kill(3)). A process-directed signal may be delivered to any one of the threads that does not currently have the signal blocked. If more than one of the threads has the signal unblocked, then the kernel chooses an arbitrary thread to which to deliver the signal.

man (7) signal

您可以使用 pthread_sigmask 来阻止特定线程的信号并通过消除将其定向到您要处理它的线程。

关于c - setitimer 的 ITIMER_PROF(SIGPROF) 是否发送到多线程和 NPTL 以及 Linux(2.6.21.7) 中的每个线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5499414/

相关文章:

c - 为什么静态变量在每次调用函数时都会初始化,但在 C 中每次都必须声明它

linux - 允许非特权用户运行特定命令

linux - 合并文件并添加文件名和目录

C++ pthread阻塞队列死锁(我认为)

c++ - 使用互斥量时出错

c - 尝试将两个尺寸为 1000*1000 的大矩阵相乘会导致段错误

c - 错误: "an array may not have elements of this type"

c - 带有互斥锁的 Pthreads 程序 - 每次都打印相同的字符串

更改特定字符的颜色

linux - Linux 模拟器 "Cannot execute binary"错误