Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (29 sloc) 635 Bytes
#!/usr/bin/env ruby
# USAGE: ps aux | grep badprocess | pskill
# Like the standard
# awk '{print $2}' | xargs kill
# ... except a little 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.join(" ")} #{procs.join(" ")}"
puts cmd
system cmd
=begin
#!/bin/bash
procs=$(grep -v grep | awk '{print $2}' | perl -pe 's/\n/ /g')
if [ "$procs" == "" ]; then
echo "no processes"
exit
fi
echo "killing $procs"
echo $procs | xargs kill "$@"
=end
Jump to Line
Something went wrong with that request. Please try again.