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:
parent
3f87f4615b
commit
ed4e9baa51
1 changed files with 8 additions and 4 deletions
|
@ -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|
|
||||||
pid = File.basename(pid_dir).to_i
|
begin
|
||||||
cmd = File.read("#{pid_dir}/cmdline").tr("\x00", ' ').strip
|
pid = File.basename(pid_dir).to_i
|
||||||
swap = File.read("#{pid_dir}/status")[/^VmSwap:\s+([0-9]+)\s+kB$/, 1].to_i
|
cmd = File.read("#{pid_dir}/cmdline").tr("\x00", ' ').strip
|
||||||
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue