Pthread threads and signals

跟風遠走 提交于 2019-12-04 03:13:46

Citing man pthreads

POSIX.1 distinguishes the notions of signals that are directed to the process as a whole and signals that are directed to individual threads. According to POSIX.1, a process-directed signal (sent using kill(2), for example) should be handled by a single, arbitrarily selected thread within the process.

There were some problems in Linux at days of glibc 2.2 and older (linuxthreads was used as pthread implementation); but since glibc 2.3-2.4 there is NPTL which is more accurate in POSIX conformance about signals.

I can only be sure that it will be delivered to one thread without this signal in signal mask?

If you are using kill - yes; to random thread which doesn't block this signal.

If so what about few signals that are delivered to particular thread, like 'SIGFPE', 'SIGSEGV',

They are delivered to particular thread, only when generated by CPU/kernel (by particular instruction in some context); not by kill utility with PID argument

if I will send them using kill shell command they will be delivered to random thread or will they be delivered to the thread that created other threads?

They will be delivered to random thread of process, kill usually sends process-wide signals. But if signal is deadly, all threads in process will be destroyed.

PS: http://www.linuxprogrammingblog.com/all-about-linux-signals?page=11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!