thread, fork, wait and popen3 
Author Message
 thread, fork, wait and popen3

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...
~



Tue, 04 Jan 2005 10:00:12 GMT  
 thread, fork, wait and popen3
Hi,

At Fri, 19 Jul 2002 10:53:00 +0900,

Quote:

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

Quote:
> 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.

--
Nobu Nakada



Tue, 04 Jan 2005 10:21:04 GMT  
 thread, fork, wait and popen3

Quote:

> 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....
  http://rm-f.net/~cout/ruby/treasures/RubyTreasures-0.4/lib/open3y.rb....

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:



  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



Tue, 04 Jan 2005 21:13:55 GMT  
 thread, fork, wait and popen3

Quote:

> Process.wait(or wait2) returns exited child process ID, it
> doesn't help you?

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



Tue, 04 Jan 2005 21:19:05 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. fork() and wait()

2. fork, exec and wait on WINDOWS?

3. Fork/exec/wait

4. How to wait until all forked process are done

5. Expect: Problems when using fork & wait

6. TclX fork/execl/wait

7. Wait after fork.

8. fork and wait

9. Using ActiveX in a forked thread...

10. SUnit Question:How to catch fail/error in forked threads

11. What it more efficient fork or thread ?

12. fork - or threading problems

 

 
Powered by phpBB® Forum Software