Pid of the other end of a popen3?

A

Alex Young

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?
 
R

Robert Klemme

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


=A0Open3.popen3("other_process") do |ior, iow, ioe|
=A0 =A0otherpid =3D ior.pid

=A0 =A0raise "Oh no!" if otherpid.nil?
=A0end


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
=3D> [nil, 2112]

See ri Open3.popen3.

Cheers

robert


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

Alex Young

Robert K. wrote in post #989166:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top