Skip to content

Instantly share code, notes, and snippets.

@brendano
Created August 14, 2008 08:38
Show Gist options
  • Save brendano/5395 to your computer and use it in GitHub Desktop.
Save brendano/5395 to your computer and use it in GitHub Desktop.
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