Module: Obfusk::Util::Process

Defined in:
lib/obfusk/util/process.rb

Constant Summary collapse

GET_AGE =
->(pid) { "ps -p #{pid} -o etime=" }

Class Method Summary collapse

Class Method Details

.age(pid) ⇒ Object

get process age information from ps



20
21
22
# File 'lib/obfusk/util/process.rb', line 20

def self.age(pid)
  ispid! pid; %x[#{GET_AGE[pid]}].gsub(/\s/, '')
end

.alive?(pid) ⇒ Boolean, Symbol

process alive?

Returns:

  • (Boolean)

    false if not alive

  • (Boolean)

    true if alive and mine

  • (Symbol)

    :not_mine if alive and not mine



28
29
30
31
32
# File 'lib/obfusk/util/process.rb', line 28

def self.alive?(pid)
  ::Process.kill 0, pid; true
rescue Errno::EPERM; :not_mine
rescue Errno::ESRCH; false
end

.ispid!(pid) ⇒ Object

Raises:

  • ArgumentError if pid is not an integer



35
36
37
# File 'lib/obfusk/util/process.rb', line 35

def self.ispid!(pid)
  pid.is_a? Integer or raise ArgumentError, 'invalid PID'
end