| Class | KillAll |
| In: |
lib/kill_all.rb
|
| Parent: | Object |
| PS | = | 'ps'.to_ocmd |
| regexp | [RW] | |
| signal | [RW] |
# File lib/kill_all.rb, line 20 def call ( aRegexp ) data = PS['a'].system data.output.open do |ps| ps.readline ps.each do |line| if line =~ /^\s*(\d+)(?:\s+\S+){3}\s+(.*)$/ pid, name = $1.to_i, $2 if name =~ aRegexp and pid != $$ @pids << pid begin Process.kill(@signal, pid) rescue raise RuntimeError, "Cannot kill #{name}:#{pid}" end end else raise RuntimeError, "bad ps output (#{line})" end end end end