Pid of the other end of a popen3?

Is it possible to get the pid of a process at the other end of an IO
returned by Open3.popen3? I’m doing something not dissimilar to this:

Open3.popen3(“other_process”) do |ior, iow, ioe|
otherpid = ior.pid

raise "Oh no!" if otherpid.nil?

end

And it always raises. Looking at the source for Open3.popen3, it looks
like the child pid gets swallowed by the double-fork. Is there any way
to get it back?


Alex

On Fri, Mar 25, 2011 at 10:58 AM, Alex Y. [email protected]
wrote:

And it always raises. Looking at the source for Open3.popen3, it looks
like the child pid gets swallowed by the double-fork. Is there any way
to get it back?

What “double fork”? It seems you are using the wrong method:

irb(main):021:0> Open3.popen3(“sleep”, “5”) {|a,b,c,t| p a.pid, t[:pid]}
nil
2112
=> [nil, 2112]

See ri Open3.popen3.

Cheers

robert

Robert K. wrote in post #989166:

On Fri, Mar 25, 2011 at 10:58 AM, Alex Y. [email protected]
wrote:

And it always raises. Looking at the source for Open3.popen3, it looks
like the child pid gets swallowed by the double-fork. Is there any way
to get it back?

What “double fork”? It seems you are using the wrong method:

irb(main):021:0> Open3.popen3(“sleep”, “5”) {|a,b,c,t| p a.pid, t[:pid]}

Sorry, I missed a vital bit of information, that being which Ruby
version I’m on:

ruby-1.8.7-p302 :003 > Open3.popen3(“sleep”, “5”) {|a,b,c,t| p a.pid; p
t[:pid]}
nil
NoMethodError: undefined method `[]’ for nil:NilClass


Alex

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=popen3+pid+ruby

might help (for me it said something at the top).
-r