Skip to content

Instantly share code, notes, and snippets.

@halferty
Last active December 23, 2015 13:48
Show Gist options
  • Save halferty/6644141 to your computer and use it in GitHub Desktop.
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)
#!/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