[zeromq-dev] ZMQ, CZMQ, threads and signal handlers

Claudio Carbone erupter at libero.it
Mon Jan 7 11:49:12 CET 2013


I've been getting more and more confused by the CZMQ recent threads 
about signal handling.
In my programs I usually install a signal handler at the beginning like so

static void s_signal_handler (int signal_value)
     if (signal_value == SIGTERM || signal_value == SIGSTOP || 
signal_value == SIGINT)
         s_interrupted = 1;
     if (signal_value == SIGALRM)
         alarm_expired = 1;
     if (signal_value == SIGTSTP)
         printf("SIGTSTP received\n");

static void s_catch_signals (void)
     struct sigaction action;
     action.sa_handler = s_signal_handler;
     action.sa_flags = 0;
     sigemptyset (&action.sa_mask);
     sigaction (SIGINT, &action, NULL);
     sigaction (SIGTERM, &action, NULL);
     sigaction (SIGALRM, &action, NULL);
     sigaction (SIGSTOP, &action, NULL);
     sigaction (SIGTSTP, &action, NULL);

int main (void){

I don't make use of CZMQ, I use ZMQ and zhelpers.h but I notice that 
sometimes my signal handler is ignored and a ZMQ one catches the signal.

I've also been incurring in thread problems without ever creating 
threads in my program.
I've been doing tests with clients and servers inside the same main, 
where I create a single context and the necessary socket and then start 
the messaging pattern: in these cases the standard output (cout or 
printf) is often absent unless I start with gdb, but then stepping 
doesn't go straight, rather it jumps as if there were multiple threads 
executing the same code.
Why is this happening?

Regards and thanks

More information about the zeromq-dev mailing list