From: Tanaka Akira Date: 2013-12-07T13:41:39+09:00 Subject: [ruby-core:58934] Re: [ruby-trunk - Feature #5446] at_fork callback API 2013/12/7 Eric Wong : > 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 I think it doesn't work with multiple thread. 2.times { Thread.new { worker = Worker.new # IO.pipe worker.pid = fork { ... } ... } } If fork for worker 1 is called between IO.pipe and fork for worker 2, pipes for worker 2 is leaked for the process for worker 1 and not inherited to the process for worker 2. I feel it is not a good example for this issue. -- Tanaka Akira