I'm writing a multithreaded program which needs to be terminated with the following bash line:
killall -QUIT -w procname
I decided to use a thread to receive some signals I need to handle, like SIGQUIT and SIGUSR1, and to ignore SIGQUIT in the others. To ignore the signal I wrote this:
struct sigaction s;
s.sa_handler=SIG_IGN;
if((sigaction(SIGQUIT,&s,NULL))==-1) {
perror("sigaction");
return -1;
}
And I wrote the following code in the thread designated to wait for signals (handlerrno is a function to check errno and exit):
sigset_t threadset;
int err, sig;
if(sigfillset(&threadset)==-1) handlerrno("Sigfillset thread stats");
if(sigdelset(&threadset,SIGQUIT)==-1) handlerrno("Sigdelset thread stats");
if(sigdelset(&threadset,SIGINT)==-1) handlerrno("Sigdelset thread stats");
if(sigdelset(&threadset,SIGTERM)==-1) handlerrno("Sigdelset thread stats");
if(sigdelset(&threadset,SIGUSR1)==-1) handlerrno("Sigdelset thread stats");
if((err=pthread_sigmask(SIG_SETMASK,&threadset,NULL))!=0)
handlerror(err,"Set sigmask thread stats");
if((err=sigwait(&threadset,&sig))!=0) handlerror(err,"Sigwait");
//I handle the signals here
However, when I launch SIGQUIT from the shell, the thread designated to wait for the signals seems to be stuck in sigwait(), so I don't really know what happens and which thread gets the signal. Is anything wrong with the code? Thank you!