-
-
Save andyjeffries/1156553 to your computer and use it in GitHub Desktop.
Process Grepper and Killer for Mac OS X
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 | |
kill = false | |
name = ARGV[0] | |
if (name == "-k") | |
kill = true | |
name = ARGV[1] | |
end | |
if name | |
ps = `ps axwu|grep -i [#{name[0..0]}]#{name[1..1000]}|grep -v " #{Process.pid}"` | |
if (ps == "") | |
puts "No processes found" | |
else | |
puts ps | |
if kill | |
ps.split("\n").each do |line| | |
pid = line[/.*?(\d+)/,1].to_i | |
if pid | |
puts "Killing #{pid}" | |
`kill -9 #{pid}` | |
end | |
end | |
end | |
end | |
else | |
puts "usage: psg [-k] name" | |
puts " Grep for a process name excluding the grep process" | |
puts " -k Kill all matching processes" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment