Forking non web processes

Eric Wong normalperson at
Fri Oct 25 20:44:35 UTC 2013

Sam Saffron <sam.saffron at> wrote:
> The only reason for this level of crazy is to get the 30% memory
> saving you do when forking off a master in Ruby 2.0s CoW friendly GC.
> I understand this is less traditional, but perfectly acceptable for
> low cost VPS hosting.
> The unicorn master does "reap/terminate" the child fork on startup, so
> you are forced to hold off on forking.

You can probably replace a worker process in the after_fork hook

(totally untested)

after_fork do |server, worker|
  if == 1
    server.listeners = [] # drop listen sockets

    # keep ticking { worker.tick = while sleep(server.timeout/2) }

Or even just fork off via your Rack app.  This will be more portable in
case you want to try a different server.  unicorn workers do nothing
special with SIGCHLD, so your app can do whatever it wants with it.

More information about the mongrel-unicorn mailing list