[zeromq-dev] signal handling and czmq

Davis Ford davisford at gmail.com
Fri Nov 9 00:20:10 CET 2012

I have an app I built that uses czmq zthread_fork to spawn an attached
thread with a pipe between parent/child.  The attached child thread does
some work in an even reactor zloop_start().  This has all been working just
fine.  Now, I'm trying to daemonize the whole application, simply b/c I
want it to launch on system boot, and have it do its work -- no
interactivity with user/console.

I built a sample gist of the code here:
https://gist.github.com/4042467that has the main pieces, pared down...

After I start the daemon, and send it the TERM signal...

$ kill -s TERM <pid>

The reactor function (do_periodic_work https://gist.github.com/4042467#L116)
is shut down,

A message is sent from the child to the parent
https://gist.github.com/4042467#L47 is called, but the msg is NULL, and so
the while loop continues, but now the child thread no longer has any work
to do, and it just sits there.  I have to send the KILL signal to make it

My signal handler on https://gist.github.com/4042467#L5 is never rung.
 This happened after I added the code to daemonize the process.

I am probably misunderstanding how czmq treats signals; I'm just trying to
devise a way to do a clean shutdown, so I can call my own _do_exit().  Any
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121108/b6f35626/attachment.htm>

More information about the zeromq-dev mailing list