Eric Wong <normalperson / yhbt.net> wrote:
> the parent hook might be less useful (especially for apps which
> fork repeatedly).

I take that back.  It can be useful for for setting up pipes/sockets for IPC
between parent and child.

Example without wrapper class and explicit IO#close:

    r, w = IO.pipe
    pid = fork do
      w.close # could be atfork_child
      ...
    end
    r.close # could be atfork_parent
    ...

However, I want to do this via callback, example with Worker class:

    class Worker
      attr_writer :pid

      def initialize
        @r, @w = IO.pipe
        Process.atfork_parent { @r.close unless @r.closed? }
        Process.atfork_child { @w.close unless @w.closed? }
      end
    end

    worker = Worker.new # IO.pipe
    worker.pid = fork { ... }
    ...

    # No need to remember what to close in parent/child