Hi:
I am looking for some hints, or possible a snippet of code that
will solve a little task I am working on.
I would like to launch multiple tasks to a load
balancer, and have the main script wait until
they are all complete. I don’t think this part
is too hard.
If that is not too much trouble, I would like to be
able to identify each task as it completes.
The icing on the cake is that I want to call each
process via popen3 so I can control what is sent
to the std ports.
Thanks for any help.
···
–
Jim Freeze
If only I had something clever to say for my comment…
~
Hi,
I would like to launch multiple tasks to a load
balancer, and have the main script wait until
they are all complete. I don’t think this part
is too hard.
If that is not too much trouble, I would like to be
able to identify each task as it completes.
Process.wait(or wait2) returns exited child process ID, it
doesn’t help you?
The icing on the cake is that I want to call each
process via popen3 so I can control what is sent
to the std ports.
Currently, no way to get child’s(really grandchild’s) pid and
its exit status, but I guess you can wait EOF on its stdout and
stderr.
···
At Fri, 19 Jul 2002 10:53:00 +0900, Jim Freeze wrote:
–
Nobu Nakada
See:
http://rm-f.net/~cout/ruby/treasures/RubyTreasures-0.4/lib/open3x.rb.html
http://rm-f.net/~cout/ruby/treasures/RubyTreasures-0.4/lib/open3y.rb.html
These are two implementations of popen3 that give you the pid. Open3X
forks and the child process remains in the same process group as the
parent. Open3Y does a double-fork like the original Open3 does.
An alternative is that you might be able to do something like the
following:
@n += 1
unique_string = “Spawning child #{@n} from process #{Process.pid}“
Open3.popen3(”#{cmd} # #{unique_string}”)
str = “ps ax --cols=10000 | grep ‘#{unique_string}’ | grep -v grep | awk ‘{print $1}’” # this could probably be implemented in ruby
child_pid = #{str}
I’ve done this when I needed to find the pid of a process that
daemonizes itself.
Hope this helps,
Paul
···
On Fri, Jul 19, 2002 at 10:53:00AM +0900, Jim Freeze wrote:
The icing on the cake is that I want to call each
process via popen3 so I can control what is sent
to the std ports.
Process.wait won’t work well with popen3:
require 'open3’
Open3.popen3(“sleep 10”)
p Process.wait
popen3_test2.rb:4:in `wait’: No child processes (Errno::ECHILD)
from popen3_test2.rb:4
Paul
···
On Fri, Jul 19, 2002 at 11:16:48AM +0900, nobu.nokada@softhome.net wrote:
Process.wait(or wait2) returns exited child process ID, it
doesn’t help you?