| Class | Uttk::Strategies::KillAll |
| In: |
lib/uttk/strategies/KillAll.rb
|
| Parent: | Strategy |
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.
# File lib/uttk/strategies/KillAll.rb, line 43 def assertion pass if @pids.empty? fail "I killed some process #{@pids.inspect}" end
# File lib/uttk/strategies/KillAll.rb, line 48 def epilogue unless @pids.empty? @log.process = @pids sleep 0.2 end end
# 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