lib/multi_timeout.rb in multi_timeout-1.0.2 vs lib/multi_timeout.rb in multi_timeout-1.0.3

- old
+ new

@@ -10,22 +10,22 @@ class << self def run(argv) options = parse_options(argv) command = options[:command] - pid = fork { exec command } + pid = Process.spawn command, :pgroup => true + gid = Process.getpgid(pid) Thread.new do now = 0 loop do break if dead?(pid) options[:timeouts].each do |signal, t| if now >= t options[:timeouts].delete([signal, t]) - puts "Killing '#{command}' with signal #{signal} after #{now} seconds" - STDOUT.flush # wait instantly terminates and sometimes hides puts - Process.kill(signal, pid) + puts "Killing '#{truncate(command, 30)}' with signal #{signal} after #{now} seconds" + Process.kill(signal, -gid) end end now += TICK sleep TICK end @@ -33,9 +33,17 @@ Process.wait2.last.exitstatus || 1 end private + + def truncate(string, count) + if string.size > count + string.slice(0, count-3) + "..." + else + string + end + end def dead?(pid) Process.getpgid(pid) false rescue Errno::ESRCH