[zeromq-dev] signal handling and czmq

Pieter Hintjens ph at imatix.com
Fri Nov 9 06:35:43 CET 2012


Hi Davis,

CZMQ traps the SIGINT and SIGTERM signals, and raises the global
zctx_interrupted when either of these hit.

You must:

1. treat any NULL returned message as an interrupt, and exit any loop
2. loop on '!ztcx_interrupted' rather than 'true' in infinite loops
3. wait/shutdown in the main process

You cannot exit successfully in a signal handler.

-Pieter


On Fri, Nov 9, 2012 at 8:20 AM, Davis Ford <davisford at gmail.com> wrote:

> 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 work.
>
> 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
> suggestions?
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121109/25455896/attachment.htm>


More information about the zeromq-dev mailing list