Subj : Re: Linux 2.4: sigwait() not getting SIGTERM To : comp.programming.threads From : loic-dev Date : Mon Feb 14 2005 02:05 pm Hi Clint! > Hi: > > We've got a threaded application and a rather strange problem with > pthreads. > > The application itself spins off a thread which monitors signals received > so that it can respond to them in a synchronous fashion. All threads are > set to block on SIGTERM (and quite a few other signals), and it then goes > into sigwait(). It *does* successfully receive SIGINT, however SIGTERM > never makes it. > > What's really odd is that when we track down the thread that's doing the > sigwait() and send it a SIGTERM directly, the signal is received! > Furthermore, we can send a signal to the entire process group and this also > seems to work as expected. > > For grins, here's the process tree that results from the application: > > foo(18233)---foo(18286)-+-foo(18287) > |-foo(18288) > |-foo(18289) > `-foo(18290) > > In our case the signal waiting thread is 18287. > > My apologies if this has been seen before. I did some Googling and did not > get any relevant hits. Yes it has. Though your are not explicetly telling on which OS/pthread implementation you are encountering your problem, my guess is: Linux with LinuxThreads. There is a well-known bug with signal: signals are delivered to the target thread, not process. That is, a kill -SIGTERM 18233 will deliver the signal to the thread "18233" and only that thread. Since all threads have blocked SIGTERM, in particular thread 18233 blocks SIGTERM upon signal reception. At this point the signal is lost. forever. Of course, if you sent SIGTERM to the sigwait'ing thread, here 18287, things will work as expected. Things work also if you send the signal to the entire process group, because in particular 18287 receives it. When you type Ctrl-C from the shell, actually SIGINT is sent to the process group: that's why SIGINT works, and SIGTERM not... By the way, note that the 'ps' command should shows up only *one* process with *one* pid, not a pid per thread (this is also a well-known limitation of LinuxThreads). This make then sense to speak of sending SIGTERM to the process foo, because there is an unique pid. The implementation will then deliver the SIGTERM to the thread sigwait'ing on it, since all threads blocks it. There is two possible solutions to your problem: either you send SIGTERM to the process group, if that's an option for you. Or you upgrade your Linux and switch to NPTL. Litterature on that topic: http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#nptl http://homepages.tesco.net/~J.deBoynePollard/FGA/linux-thread-problems.html http://linuxdevices.com/articles/AT6753699732.html http://people.redhat.com/drepper/nptl-design.pdf Hope this help, Loic. .