T
trickyvail
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.
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.