ARGV.length() == 1 or begin $stderr.print("usage: #{$0} pattern\n"); exit(1) end pat = Regexp.new(ARGV[0]) IO.popen("ps -w -w x -o'pid,command'") {|PS| PS.gets # discard header line PS.each {|line| proc = line.split[0].to_i if line =~ pat and proc != Process.pid then print line.chomp begin print "? " answer = $stdin.gets end until answer =~ /^[yn]/i if answer =~ /^y/i then Process.kill(9, proc) sleep(1) begin # expect exception (process gone) Process.kill(0, proc) $stderr.print("unsuccessful; sorry\n"); exit(1) rescue # handler -- do nothing end end end } }