Last active
May 26, 2019 04:43
-
-
Save asender/71b9746ae16602bfad0c268e5e6652fe 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 | |
options = { | |
count: 10 | |
} | |
lines = `grep '^Swap' /proc/*/smaps 2>/dev/null`.split("\n") | |
pid2swap = {} | |
puts "Swap space PID Process" | |
puts "========== ===== =======" | |
lines.each do |line| | |
if !line.match(/\/proc\/(\d+)\/smaps:Swap:\s*(\d+) kB/) | |
puts "Bad line: " + line | |
next | |
end | |
pid, kb = $1, $2 | |
pid2swap[pid] = pid2swap[pid].to_i + kb.to_i | |
end | |
pid2swap.sort {|a,b| -a[1] <=> -b[1] }.slice(0...options[:count]).each do |pid, kb| | |
psout = `ps -p #{pid} -o args=`.strip | |
if psout.empty? | |
printf "%s kB (no longer running)\n", kb | |
else | |
printf "%s kB %s %s\n", kb, pid, psout | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment