Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.