10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/multi_timeout.rb', line 10
def run(argv)
options = parse_options(argv)
command = options[:command]
pid = Process.spawn(command)
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"
Process.kill(signal, pid)
end
end
now += TICK
sleep TICK
end
end
Process.wait2.last.exitstatus || 1
end
|