Roger's woze

September 1, 2009

how to determine if a subprocess has died in ruby

Filed under: Uncategorized — rogerdpack @ 9:40 pm
require 'timeout'
a = IO.popen("command")
# later
begin
 Timeout::timeout(0.01) { Process.wait(a.pid) }
  puts 'shows signs of being dead'
rescue TimeoutError
 puts 'probably still alive'
end

1 Comment »

  1. this is for windows–for Linux you can use Process::WNOHANG [or something like that] splendidly to see if it is dead or not.

    Comment by rogerdpack — September 2, 2009 @ 12:53 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress