Skip to content

Instantly share code, notes, and snippets.

@brendano brendano/pskill
Created Aug 14, 2008

Embed
What would you like to do?
pskill
#!/usr/bin/env ruby
# USAGE: ps wwaux | grep badprocess | pskill
# Like awk '{print $2}' | xargs kill, except somewhat smarter
class Array
def map_if(&b)
map(&b).select{|x| x}
end
end
procs = STDIN.readlines.map_if{|l| l !~ /grep/ && l.split[1]}
if procs.empty?
puts "no processes"
exit
end
# puts "killing #{procs.join(" ")}"
cmd = "kill #{ARGV} #{procs.join(" ")}"
puts cmd
system cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.