POSIX 线程和 SIGSEGV [英] POSIX Threads and SIGSEGV
本文介绍了POSIX 线程和 SIGSEGV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含 10 多个线程的系统.我有一个信号处理程序来捕获 SIGSEGV.如果一个线程生成 SIGSEGV,那么该信号会发送到所有线程,还是只发送到生成该信号的线程?
I have a system with 10+ threads. I have a signal handler to catch SIGSEGV. if one thread generates SIGSEGV, does that signal go to all threads, or just to the thread that generated the signal?
推荐答案
SIGSEGV
是一个同步信号.它将被传递给导致无效内存访问的线程.来自 signal(7)
:
SIGSEGV
is a synchronous signal. It'll be delivered to the thread that caused the invalid memory access. From signal(7)
:
可能会为整个进程(例如,当使用kill(2)
发送时)或针对特定线程(例如,某些信号,例如作为SIGSEGV
和SIGFPE
,作为执行特定机器语言指令是线程导向的,信号也是面向线程的使用pthread_kill(3)
的特定线程).一个过程导向的信号可能是传递给当前没有信号的任一线程阻止.如果多个线程解除了信号阻塞,则内核选择一个任意线程来传递信号.
A signal may be generated (and thus pending) for a process as a whole (e.g., when sent usingkill(2)
) or for a specific thread (e.g., certain signals, such asSIGSEGV
andSIGFPE
, generated as a consequence of executing a specific machine-language instruction are thread directed, as are signals targeted at a specific thread usingpthread_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.
这篇关于POSIX 线程和 SIGSEGV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文