class Ps_process

Attributes

c[R]
children[RW]
cmd[R]
pid[R]
ppid[R]
stime[R]
time[R]
tty[R]
uid[R]

Public Class Methods

new(string = '') click to toggle source
# File lib/Unix/Ps_process.rb, line 18
def initialize (string = '')
  @children = 0

  decode(string) unless string.empty?
end

Public Instance Methods

decode(string) click to toggle source
# File lib/Unix/Ps_process.rb, line 24
def decode(string)

  regexp = %r{(\w+)\s+ #UID
  (\d+)\s+ #PID
  (\d+)\s+ #PPID
  (\d+)\s+ # CPU TIME (C)
  (\w{3}\d{1,2}|\d{1,2}:\d{1,2}|)\s+ #Strat Time
  (\?|pts\/\d+|tty\d+|)\s+ #Console
  (\d{1,2}:\d{1,2}:\d{1,2}|\d+-\d{1,2}:\d{1,2}:\d{1,2}|\d{1,2}:\d{1,2})\s+  #TIME
  (.*) # command
  }x
  match = regexp.match(string)

  unless match
    puts string
    puts regexp
    puts match
    puts "regexp couldn't decode string #{string}"
    raise
  end

  @uid   = match[1]
  @pid   = match[2].to_i
  @ppid  = match[3].to_i
  @c     = match[4].to_i # C     pcpu         cpu utilization
  @stime = match[5]
  @tty   = match[6]
  @time  = match[7]
  @cmd   = match[8]
end