Subj : Re: sigwait() is not catching SIGUSR1 signal To : comp.programming.threads,comp.unix.programmer From : Roopa Date : Fri Mar 11 2005 02:17 am Neelakantan wrote: > Hi, > > i have a problem with sigwait() in a multithreaded program. > > In this program some thread will be generating the signal SIGUSR1 at > some time(asynchronously) and there is a dedicated thread for handling > the asynchronous(SIGUSR1 in my case) signals. > > The sinal handling thread uses sigwait() to catch the signal, however > the signal is not caught by the sigwait() function. I have blocked the > signal SIGUSR1 before the threads are created aswell before the sigwait() is called. > If its not caught then your registered signal handler isnt registered properly with the OS. ! You need to override the default signal handling by OS with your signal handlers at the right place :-) May be reading your OS documentation on signal handlers might be of some clue/help of howto accomplish it. - Roopa > I have included a variant of the program. > > Any help will be highly appreciated. > > Thanks and regards, > > Neelakantan > > ***************************************************************** > OS : Redhat 9 kernel version 2.4.20 > > Compiler: g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5). > > Note: if i send the signal SIGUSR1 from the command prompt, > the signal has been caught. > > **************** sinal.cpp ************************************ > #include > #include > #include > #include > #include > using namespace std; > void* fun(void* arg) > { > int i = 0; > while(i<10) > { > sleep(2); > kill(getpid(),SIGUSR1); > cout << "SIGUSR1 Has been sent" << i++ << endl; > } > return NULL; > } > int main() > { > pthread_t tid; > sigset_t set; > sigemptyset(&set); > sigaddset(&set, SIGUSR1); > sigaddset(&set, SIGINT); > pthread_sigmask(SIG_BLOCK, &set, NULL); > int status = pthread_create(&tid,0,fun,0); > if (status != 0) > { > cout << "Thread Creation Failed" << endl; > exit(0); > } > int signal = 0; > while(true) > { > sigwait(&set,&signal); > if (signal == SIGUSR1) > { > cout << "SIGUSR1 signal recieved" << endl; > break; > } > if(signal == SIGINT) > { > cout << "SIGINT signal recieved" << endl; > break; > } > } > cout << "Main is exiting" << endl; > exit(0); > } > ******************* signal.cpp ends *************************** .