From the zeroMQ documentation for zmq_recv (), you can expect an EINTR return if a signal is received when it is running.
Generating signals right in the middle of a call to zmq_recv() would be a difficult task for any test. Fortunately, the gperftools generating a ton of SIGPROF detected this subtle โerrorโ in your code.
This one should be properly handled in your code, since the zeroMQ framework is an elegant control. Repeat logic can be as simple as modifying an existing call:
rc = zmq_recv (socket, &part, 0);
with a new one (with retry logic) as follows:
/* Block until a message is available to be received from socket * Keep retrying if interrupted by any signal */ rc = 0; while(rc != EINTR) { rc = zmq_recv (socket, &part, 0); }
Also set the signal handler function in your program. You can simply ignore the interrupt due to SIGPROF and continue the retry.
Finally, you can process certain signals and act accordingly. For example, gracefully terminating your program, even if the user presses CTRL + C while your program is waiting on zmq_recv() .
/* Block until a message is available to be received from socket * If interrupted by any signal, * - in handler-code: Check for signal number and update status accordingly. * - in regular-code: Check for status and retry/exit as appropriate */ rc = 0; while(rc != EINTR && status == RETRY) { rc = zmq_recv (socket, &part, 0); }
In the interest of keeping the code โclean,โ you will be better served by using the above snippet to write your own shell of static inline functions around zmq_recv() , which you can call in your program.
Regarding the decision to make zmq_recv() return EINTR after receiving the signals, you can check out this article, which talks about a worse philosophy behind such a design, which is simpler from the point of view of implementation.
UPDATE Documented code for signal processing in the context of zmq_recv() is available at git.lucina.net/zeromq-examples.git/tree/zmq-camera.c . It corresponds to the same lines as explained above, but it looks well tested and ready to use with detailed comments, kindly showered (yayyy zeromq!).