Class: PosixPsutil::PsutilHelper::Processes
- Inherits:
-
Object
- Object
- PosixPsutil::PsutilHelper::Processes
- Defined in:
- lib/posixpsutil/linux/helper.rb
Overview
There is a module called Process in ruby. To distinguish from it, I name this one with ‘Processes`.
Direct Known Subclasses
Class Method Summary collapse
-
.get_all_inodes ⇒ Object
format: inodes= { inode1 => [[pid, fd], [pid, fd], …] inode2… }.
-
.get_proc_inodes(pid) ⇒ Object
be aware of Permission denied.
-
.pids ⇒ Object
Returns a list of PIDs currently running on the system.
Class Method Details
.get_all_inodes ⇒ Object
format: inodes= {
inode1 => [[pid, fd], [pid, fd], ...]
inode2...
}
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/posixpsutil/linux/helper.rb', line 51 def self.get_all_inodes() inodes = {} self.pids.each do |pid| begin inodes.merge!(self.get_proc_inodes(pid)){ |k, v1, v2| v1 + v2} rescue SystemCallError => e # Not Permission denied? raise unless [Errno::ENOENT::Errno, Errno::ESRCH::Errno, Errno::EPERM::Errno, Errno::EACCES::Errno].include?(e.errno) end end inodes end |
.get_proc_inodes(pid) ⇒ Object
be aware of Permission denied
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/posixpsutil/linux/helper.rb', line 26 def self.get_proc_inodes(pid) inodes = {} Dir.entries("/proc/#{pid}/fd").each do |fd| next if fd == '.' || fd == '..' # get actual path begin inode = File.readlink("/proc/#{pid}/fd/#{fd}") # check if it is a socket if inode.start_with? 'socket:[' inode = inode[8...-1].to_i inodes[inode] ||= [] inodes[inode].push([pid, fd.to_i]) end rescue SystemCallError next end end inodes end |
.pids ⇒ Object
Returns a list of PIDs currently running on the system.
21 22 23 |
# File 'lib/posixpsutil/linux/helper.rb', line 21 def self.pids() Dir.entries('/proc').map(&:to_i).delete_if {|x| x == 0} end |