Created
August 14, 2008 08:38
-
-
Save brendano/5395 to your computer and use it in GitHub Desktop.
pskill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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