Class: RPS::LinuxProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/rps/linux_process.rb

Constant Summary collapse

NULL =
"\000"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ LinuxProcess

Returns a new instance of LinuxProcess.



9
10
11
# File 'lib/rps/linux_process.rb', line 9

def initialize(dir)
  @dir = dir
end

Class Method Details

.allObject



5
6
7
# File 'lib/rps/linux_process.rb', line 5

def self.all
  Dir['/proc/*'].map { |dir| new(dir) if File.basename(dir) =~ /^\d+$/ }.compact
end

Instance Method Details

#command_lineObject



33
34
35
# File 'lib/rps/linux_process.rb', line 33

def command_line
  @command_line ||= File.read(cmdline_path).split(NULL)
end

#cwdObject



29
30
31
# File 'lib/rps/linux_process.rb', line 29

def cwd
  @cwd ||= File.readlink(cwd_path)
end

#environmentObject



37
38
39
40
41
42
43
44
# File 'lib/rps/linux_process.rb', line 37

def environment
  @environment ||= (
    strings = File.read(environ_path).split(NULL)
    data = strings.map { |e| e.split("=") }

    Hash[data]
  )
end

#exeObject



21
22
23
# File 'lib/rps/linux_process.rb', line 21

def exe
  @exe ||= File.readlink(exe_path)
end

#pidObject



25
26
27
# File 'lib/rps/linux_process.rb', line 25

def pid
  @pid ||= Integer(File.basename(@dir))
end

#readable?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rps/linux_process.rb', line 13

def readable?
  File.readable? exe_path
end

#ruby?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rps/linux_process.rb', line 17

def ruby?
  exe.include? "ruby" # is this good enough?
end