[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

open3 throws exception when preceded by fork

trickyvail

7/14/2008 7:09:00 PM

I am attempting to create a daemon that (when required) spawns off
child processes to perform "jobs". It is important that this daemon
does not block so it can start concurrent jobs, and that it knows when
jobs have completed. Some of the jobs are written in C++ and send
their output over standard error (stderr).

Here's an outline of my daemon program.

#!/usr/bin/ruby
require 'open3'
stop = false
Signal.trap('CLD') do
child = Process.wait
puts "child #{child} closed."
stop = true
end
child = Kernel.fork()
if(child == nil)
stdin, stdout, stderr =
Open3.popen3('program_that_sends_output_to_stderr')
stderr.each do |line|
puts line
end
Kernel.exit!
end
while(! stop)
sleep 5
end
puts "finished"

When tested separately the fork and popen3 calls seem to be just what
I need to meet my objectives, but when they are run sequentially the
popen3 call throws an exception:
Error: "/usr/lib/ruby/1.8/open3.rb:75:in `waitpid': No child processes
(Errno::ECHILD)"

Is this a limitation of Open3? Any alternative approaches would be
gratefully received.
Thank you.
4 Answers

ara.t.howard

7/14/2008 8:52:00 PM

0


On Jul 14, 2008, at 1:05 PM, trickyvail wrote:

> s this a limitation of Open3? Any alternative approaches would be
> gratefully received.


require 'rubygems'
require 'slave' # gem install slave


class Server
def run job
system job
end
end

slave = Slave.new{ Sever.new }
server = slave.object

server.run 'echo "this is in another process you do not have to ever
worry about"'

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




trickyvail

7/14/2008 11:51:00 PM

0

On Jul 14, 2:52 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> require 'rubygems'
> require 'slave' # gem install slave
>
> class Server
> def run job
> system job
> end
> end
>
> slave = Slave.new{ Sever.new }
> server = slave.object
>
> server.run 'echo "this is in another process you do not have to ever
> worry about"'

Thank you for you reply. Unfortunately I am unable to utilize the
slave ruby gem (and open4 gem also) due to some rubygems package
corruption? on my Ubuntu machine. I've given up fighting with it and
come up with a different solution.

daemon:
#!/usr/bin/ruby
stop = false
Signal.trap('CLD') do
child = Process.wait
puts "child #{child} closed."
stop = true
end
exec('./job.rb') if fork.nil?
while(! stop)
puts 'not finished, do some other stuff'
sleep 5
end
puts "finished"

job:
#!/usr/bin/ruby
require 'open3'
stdin, stdout, stderr = Open3.popen3('real_job_binary')
stderr.each do |line|
puts line
end

This way the calls to fork and open3 are isolated in different ruby
interpreter instances where they can't interfere with each other.

ara.t.howard

7/14/2008 11:58:00 PM

0


On Jul 14, 2008, at 5:50 PM, trickyvail wrote:

>
> Thank you for you reply. Unfortunately I am unable to utilize the
> slave ruby gem (and open4 gem also) due to some rubygems package
> corruption? on my Ubuntu machine. I've given up fighting with it and
> come up with a different solution.

the tgz files are on rubyforge. just unpack and run

'sudo ruby install.rb'

cheers.

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




China Blue Veins

5/3/2014 3:48:00 AM

0

In article <536462AE.200B01F4@hotmail.com>,
RichTrasky <traRvEskyMOVE@hotmail.com> wrote:

> > > (Deuteronomy 22:20-21)
> >
> > It all sounds a little Islamic, doesn't it?
>
> No. It sounds biblical.
>
> Judaism is much older than Islam. You knew that, right?

Jews expect only Jews to pay attention to Mosaic Law. Moslems expect everyone to
obey their laws.

CINOs ignore Acts and the Gospels and expect everyone to obey their peculiar
version of Mosaic Law.

--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted.
'I desire mercy, not sacrifice.'
Icke's razor: Given two equally plausible explanations, choose the weirder.