#include <iostream> #include <signal.h> #include <unistd.h> using namespace std; void sighandler(int sig) { cout << "signal received" << endl; } int main() { int pid= getpid(); cout << pid << endl; signal( SIGUSR1, sighandler ); sigset_t accept; sigaddset( &accept, SIGUSR1 ); int s; sigwait(&accept, &s); cout << s << endl; return 0; } When I run this program and send a SIGUSR1 signal to it via "kill -s SIGUSR1 $pid" it just outputs the number of the signal (10) but not the text in sighandler. I don't understand why. This is on a Linux System.
sigemptyset(&accept)prior to yoursigaddset.coutin a signal handler invokes undefined behavior. Don't do that, write a signal handler correctly.