Skip to content

Instantly share code, notes, and snippets.

@Geesu
Created December 5, 2016 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geesu/018fcc388e0f377e6bdca312ab817b90 to your computer and use it in GitHub Desktop.
Save Geesu/018fcc388e0f377e6bdca312ab817b90 to your computer and use it in GitHub Desktop.
Limit VTDecoderXPCService using cputhrottle
#!/usr/bin/env ruby
# Configure the below
process_name = 'VTDecoderXPCService'
cpu_percentage = 10
raise 'Must run as root' unless Process.uid == 0
restricted_pids = []
throttle_pids = []
begin
loop do
pids = `pgrep "#{process_name}"`
if pids
pids = pids.split("\n")
pids.each do |pid|
next if restricted_pids.include? pid
puts "Restricting process ID #{pid}"
restricted_pids << pid
throttle_pids << Process.spawn("/usr/local/bin/cputhrottle #{pid} #{cpu_percentage}")
end
end
sleep 1
end
rescue SystemExit, Interrupt
throttle_pids.each do |pid|
begin
puts "Killing cputhrottle process #{pid}"
Process.kill('QUIT', pid)
rescue Errno::ESRCH
# process exited normally
end
end
raise
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment