1
0
Fork 0
mirror of https://github.com/nishiki/swapus.git synced 2024-11-26 14:03:05 +00:00

fix: no raise error if a process is terminated during the swapus execution

This commit is contained in:
Adrien Waksberg 2018-02-07 17:01:25 +01:00
parent 3f87f4615b
commit ed4e9baa51

View file

@ -25,11 +25,15 @@ class SwapUsage
def get_processes def get_processes
Dir['/proc/[0-9]*'].map do |pid_dir| Dir['/proc/[0-9]*'].map do |pid_dir|
begin
pid = File.basename(pid_dir).to_i pid = File.basename(pid_dir).to_i
cmd = File.read("#{pid_dir}/cmdline").tr("\x00", ' ').strip cmd = File.read("#{pid_dir}/cmdline").tr("\x00", ' ').strip
swap = File.read("#{pid_dir}/status")[/^VmSwap:\s+([0-9]+)\s+kB$/, 1].to_i swap = File.read("#{pid_dir}/status")[/^VmSwap:\s+([0-9]+)\s+kB$/, 1].to_i
@processes[pid] = { cmd: cmd, swap: swap } if swap.positive? @processes[pid] = { cmd: cmd, swap: swap } if swap.positive?
rescue Errno::ENOENT
next
end
end end
end end