Class: Uttk::Strategies::KillAll
- Inherits:
-
Strategy
show all
- Includes:
- Concrete
- Defined in:
- lib/uttk/strategies/KillAll.rb
Overview
I kill all the process that match my regexp attribute by sending my signal attribute. I’m unfortunately not compatible with all OS since I depend on the ps program.
Instance Attribute Summary
Attributes inherited from Strategy
#status
Instance Method Summary
collapse
Methods inherited from Strategy
#abort, #assert_cmd, #assign, #clean_instance_variables, #display_unexpected_exc, #display_unexpected_synflow_exc, #fail, #initialize, #initialize_flow_factory, #mk_system_runner, #name=, #pass, #raise_error, #reject, #run, #running?, #skip, #skip_if_cached, #skip_pass, #skip_wrt_rpath_and_rpath_exclude, #strategy, #strategy=, #symbols=, #symtbl, #symtbl=, #testify, #timeout=, to_form, #to_s, to_yaml_type, #wclass=
Instance Method Details
#assertion ⇒ Object
43
44
45
46
|
# File 'lib/uttk/strategies/KillAll.rb', line 43
def assertion
pass if @pids.empty?
fail "I killed some process #{@pids.inspect}"
end
|
48
49
50
51
52
53
|
# File 'lib/uttk/strategies/KillAll.rb', line 48
def epilogue
unless @pids.empty?
@log.process = @pids
sleep 0.2
end
end
|
17
18
19
20
|
# File 'lib/uttk/strategies/KillAll.rb', line 17
def prologue
super
@pids = []
end
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/uttk/strategies/KillAll.rb', line 22
def run_impl
IO.popen('ps a') do |ps|
ps.readline
ps.each do |line|
if line =~ /^\s*(\d+)(?:\s+\S+){3}\s+(.*)$/
pid, name = $1.to_i, $2
if name =~ @regexp
@pids << pid
begin
Process.kill(@signal, pid)
rescue
raise RuntimeError, "Cannot kill #{name}:#{pid}"
end
end
else
raise RuntimeError, 'bad ps output'
end
end
end
end
|