Skip to content

Instantly share code, notes, and snippets.

@tgxworld
Created October 12, 2017 09:24
Show Gist options
  • Save tgxworld/e049b469f17af9d8d418be6cdcf33280 to your computer and use it in GitHub Desktop.
Save tgxworld/e049b469f17af9d8d418be6cdcf33280 to your computer and use it in GitHub Desktop.
sum = 0
processes = []
Dir["/proc/*/fd"].each do |dir|
if dir =~ /proc\/(\d+)\/fd/
count = Dir[dir + '/*'].count
sum += count
if count > 400
pid_info = `ps -p #{Regexp.last_match[1]} -o args=`.chomp
processes << [pid_info, count]
end
end
end
processes.sort_by { |_, count| count }.each do |pid_info, count|
puts "#{pid_info} || #{count}"
end
puts "Total Allocated FDs: #{sum}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment