Last active
December 23, 2015 13:48
-
-
Save halferty/6644141 to your computer and use it in GitHub Desktop.
Commit Unix process genocide (Or just kill jetty when ctrl-c doesn't work)
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 | |
require 'colorize' | |
search = ARGV[0] | |
if search | |
results = `ps aux | grep -i #{search} | grep -v grep | grep -v ruby`.split("\n") | |
if results.size > 0 | |
puts "Kill these processes???".red | |
puts results.map { |m| m.sub(/([^\s]*\s*){10}/, '') }.join("\n").yellow | |
print "(y/n):".red | |
begin | |
system 'stty raw -echo' | |
str = STDIN.getc | |
ensure | |
system 'stty -raw echo' | |
puts '' | |
end | |
if str.downcase == "y" | |
pids = results.map { |m| m.split[1] } | |
puts "killing processes " + pids.join(", ") | |
pids.each { |pid| system "kill -9 #{pid}" } | |
end | |
else | |
puts "No processes match" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment