[zeromq-dev] Is it ok to fork() a new process with an active context?

Matt Connolly matt.connolly at me.com
Sun Jan 5 21:39:58 CET 2014

Hi Tom, 

Closing the inherited context and creating a new one is the way it should work. 

I added some code to support destroying the inherited context after fork a few months back. This code shuts down the io threads and closes the file descriptors used for internal messaging between threads in zmq.

The place where I'm less confident is about closing the file descriptors for any open socket connections. 

However, I haven't battle tested this yet. If their are issues, please let me know and I'll try to help as this is a feature I want to use too. 


> On 6 Jan 2014, at 12:45 am, Tom Nakamura <tnakamura at eml.cc> wrote:
> Suppose I want to write some sort of server which forks a new worker
> process for every incoming connection (on Linux/Unix).  Does it suffice
> to fork() a child process, immediately close the inherited
> context/sockets in the child and create new context/socket to talk to
> the parent?  Or must I prefork before creating a context in the parent?
> The reason I want to use processes instead of threads is because the
> "workers" in my particular project are 3rd party programs that I must
> run as a separate process (no API to integrate into a C program). 
> Tom
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list