Hello
I want to use setitimer()
(or alarm()
) in multithreaded process in linux 2.6+ with NPTL-enabled libc. Which thread will receive sigalarm (SIGALRM)
from kernel?
Thanks.
Hello
I want to use setitimer()
(or alarm()
) in multithreaded process in linux 2.6+ with NPTL-enabled libc. Which thread will receive sigalarm (SIGALRM)
from kernel?
Thanks.
From signal(7) man page:
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.
Now, alarm(2) man page says that:
alarm() arranges for a SIGALRM signal to be delivered to the process in seconds seconds.
So, the signal is delivered to a process (a signal might be directed at certain thread too) and thus you do not know which of the threads will receive it.
The same with setitimer(2):
When any timer expires, a signal is sent to the process, and the timer (potentially) restarts.
You could block SIGALARM
in all your threads except one, then you could be certain that it will be delivered to that only thread. Assuming you are using pthreads, you can block signals with pthread_sigmask().