Class: Ps_process

Inherits:
Object
  • Object
show all
Defined in:
lib/Unix/Ps_process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = '') ⇒ Ps_process

Returns a new instance of Ps_process.



18
19
20
21
22
# File 'lib/Unix/Ps_process.rb', line 18

def initialize (string = '')
  @children = 0

  decode(string) unless string.empty?
end

Instance Attribute Details

#cObject (readonly)

Returns the value of attribute c.



11
12
13
# File 'lib/Unix/Ps_process.rb', line 11

def c
  @c
end

#childrenObject

Returns the value of attribute children.



16
17
18
# File 'lib/Unix/Ps_process.rb', line 16

def children
  @children
end

#cmdObject (readonly)

Returns the value of attribute cmd.



15
16
17
# File 'lib/Unix/Ps_process.rb', line 15

def cmd
  @cmd
end

#pidObject (readonly)

Returns the value of attribute pid.



9
10
11
# File 'lib/Unix/Ps_process.rb', line 9

def pid
  @pid
end

#ppidObject (readonly)

Returns the value of attribute ppid.



10
11
12
# File 'lib/Unix/Ps_process.rb', line 10

def ppid
  @ppid
end

#stimeObject (readonly)

Returns the value of attribute stime.



12
13
14
# File 'lib/Unix/Ps_process.rb', line 12

def stime
  @stime
end

#timeObject (readonly)

Returns the value of attribute time.



14
15
16
# File 'lib/Unix/Ps_process.rb', line 14

def time
  @time
end

#ttyObject (readonly)

Returns the value of attribute tty.



13
14
15
# File 'lib/Unix/Ps_process.rb', line 13

def tty
  @tty
end

#uidObject (readonly)

Returns the value of attribute uid.



8
9
10
# File 'lib/Unix/Ps_process.rb', line 8

def uid
  @uid
end

Instance Method Details

#decode(string) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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