Created
November 2, 2011 14:33
-
-
Save dlongmuir/1333787 to your computer and use it in GitHub Desktop.
BTServer killer
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 | |
# Kill crazy BTServer processes when the iPad simulator is running and | |
# you wake your Mac from sleeping | |
seconds_between_checking = 30 | |
kill_threshold_percent = 10.0 | |
while true do | |
ps_out_full = %x[ps aux | grep BTServer] | |
ps_out = [] | |
cpu = "" | |
pid = "" | |
ps_out_full.each_line do |line| | |
if !line.include? "grep" and !line.include? "launchctl" | |
ps_out = ps_out_full.split | |
cpu = ps_out[2] | |
pid = ps_out[1] | |
break | |
end | |
end | |
# puts %x[ps aux | grep BTServer] | |
# Make sure it is launched | |
if ps_out.empty? | |
print "#{Time.now} BTServer not running." | |
else | |
print "#{Time.now} BTServer running at #{cpu}% " | |
1.upto( cpu.to_f * 10.0 ) { print "*" } #cheesy histogram | |
end | |
if !ps_out.empty? and cpu.to_f > kill_threshold_percent | |
print "killing it (pid: #{pid}) #{%x[kill #{pid}]}" | |
sleep(1) | |
else | |
sleep(seconds_between_checking) | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not the cleanest rb but does the trick