Skip to content

Instantly share code, notes, and snippets.

@dlongmuir
Created November 2, 2011 14:33
Show Gist options
  • Save dlongmuir/1333787 to your computer and use it in GitHub Desktop.
Save dlongmuir/1333787 to your computer and use it in GitHub Desktop.
BTServer killer
#!/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
@dlongmuir
Copy link
Author

Not the cleanest rb but does the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment