blob: 1fa3878a762b8ec8631c5f085795271592773dad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
class Array
def max_index
self.index(self.max)
end
def is_subset_of? other
self.each { |i|
if other.include? i
return false
end
}
return true
end
end
def spawn_with_timeout cmd, t=4, debug=false
require 'timeout'
STDERR.write cmd+"\n" if debug
pipe_in, pipe_out = IO.pipe
pid = Process.spawn(cmd, :out => pipe_out)
begin
Timeout.timeout(t) { Process.wait pid }
rescue Timeout::Error
return ""
# accept the zombies
#Process.kill('TERM', pid)
end
pipe_out.close
return pipe_in.read
end
|