Skip to content

Instantly share code, notes, and snippets.

@halferty
Created April 10, 2020 19:15
Show Gist options
  • Save halferty/e2bedba20667cb7f07f6bc7439dddc51 to your computer and use it in GitHub Desktop.
Save halferty/e2bedba20667cb7f07f6bc7439dddc51 to your computer and use it in GitHub Desktop.
End processes matching string
#!/usr/bin/env ruby
require "io/console"
keywords = ARGV.reject { |arg| arg.length < 4 }
`ps auxww`.split(/\n/)
.reject { |line| line.include?("killify") }
.filter { |line| keywords.any? { |k| line.include?(k) } }
.map { |line| line.split(/\s+/) }
.map { |line| [line[1], line[10..-1].join(" ")] }
.each { |line|
puts "Kill process #{line[0]}? (y/N) (with CLI \"#{line[1]}\")"
if STDIN.getch.downcase === 'y'
puts `kill -9 #{line[0]}`
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment