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

--
Posted via http://www.ruby-forum.com/.

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

···

On Fri, Mar 25, 2011 at 10:58 AM, Alex Young <alex@blackkettle.org> wrote:

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?

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

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

···

--
Posted via http://www.ruby-forum.com/.

Robert K. wrote in post #989166:

···

On Fri, Mar 25, 2011 at 10:58 AM, Alex Young <alex@blackkettle.org> > 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

--
Posted via http://www.ruby-forum.com/\.