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.

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