Created
April 6, 2011 02:52
-
-
Save nesquena/905040 to your computer and use it in GitHub Desktop.
Kills all processes matching a pattern (killmatch)
This file contains hidden or 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 | |
# sudo killmatch Rails | |
unless ARGV[0] | |
puts "Specify a pattern to kill! i.e killmatch Rails" | |
exit | |
end | |
pids = `ps -ef | grep -vE \"^USER|grep|killmatch\" | grep #{ARGV[0]}" | awk '{print $2;}`.chomp.split("\n") | |
pids.each do |pid| | |
puts "Killing process #{ARGV[0]} #{pid}'" | |
system "kill -9 #{pid}" | |
end |
This file contains hidden or 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 | |
# sudo killmatch Rails | |
unless ARGV[0] | |
puts "Specify a pattern to kill! i.e killmatch Rails" | |
exit | |
end | |
processes = `ps -ef | grep #{ARGV[0]}`.split("\n").map { |s| s.gsub(/\s+/, ' ').strip } | |
processes.reject! { |p| p =~ /killmatch/ || p =~ /grep/ || p =~ /ps -ef/ } | |
process_data = processes.map { |p| p.split(" ") } | |
process_data.each do |pd| | |
puts "Killing process '#{pd[0]}' with pid '#{pd[1]}'" | |
system("kill -9 #{pd[1]}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There isn't an option in passanger to kill process after they are idle for XX time? I've the same problem.