Last active
December 19, 2015 01:58
-
-
Save pcarrier/5879220 to your computer and use it in GitHub Desktop.
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 | |
require 'json' | |
VERBOSE = (ARGV.include? '-v') | |
rules = JSON::parse(File.read('/etc/oomsaver.json')).collect do |re, score| | |
[Regexp.new(re), score] | |
end | |
Dir['/proc/[0-9]*'].each do |dir| | |
begin | |
comm = File.read(File.join(dir, 'comm')).strip | |
cmdline = File.read(File.join(dir, 'cmdline')).gsub('\0', ' ').strip | |
descr = "#{comm}@#{cmdline}" | |
_, score = rules.find {|reg, _| reg === descr} | |
if score | |
puts "#{descr} matches" if VERBOSE | |
adj_path = File.join(dir, 'oom_score_adj') | |
old_score = File.read(adj_path).to_i | |
unless score == old_score | |
File.write adj_path, score | |
puts "Adjusted #{descr} (#{File.basename dir}) to #{score}" | |
end | |
else | |
puts "#{descr} doesn't match" if VERBOSE | |
end | |
rescue | |
# PIDs come and go | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment