Class: RLPS::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rlps/helper/parser.rb

Overview

This class parses Linux’s /proc/ directory status file.

Class Method Summary collapse

Class Method Details

.process_from_dir(dir) ⇒ Object

This method gets a /proc/ directory, then it parses its status file and returns a new RLPS::Process object.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rlps/helper/parser.rb', line 9

def self.process_from_dir(dir)
  status = {}
  File.open(File.join(File.join('/proc', dir), 'status'), 'r') do |f|
    f.each_line do |line|
      res = line.match(/(^\w+):\s*(\d+|[\w\(\)\-]+)?/).captures
      res[1] ||= nil
      status[res[0]] = res[1]
    end
  end
  RLPS::Process.new name: status['Name'], pid: status['Pid'].to_i
  # TODO: add more information
end