Class: Jah::Prok

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/jah/commands/prok.rb

Constant Summary collapse

BANLIST =
[/^ata/, /^init$/, /^scsi_/, /\/\d$/, /agetty/ ]

Constants included from Command

Command::COMM

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

included

Constructor Details

#initialize(args) ⇒ Prok

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND



31
32
33
34
35
36
37
38
# File 'lib/jah/commands/prok.rb', line 31

def initialize(args)
  return unless args[0]
  @user, @pid, @cpu, @mem, @vsz, @rss, @tty, @stat, @start, @time, *@comm = args

  @pid, @vsz, @rss = [@pid, @vsz, @rss].map(&:to_i)
  @cpu, @mem = [@cpu, @mem].map(&:to_f)
  @comm = @comm.join(" ")
end

Instance Attribute Details

#commObject (readonly)

Returns the value of attribute comm.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def comm
  @comm
end

#cpuObject (readonly)

Returns the value of attribute cpu.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def cpu
  @cpu
end

#memObject (readonly)

Returns the value of attribute mem.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def mem
  @mem
end

#pidObject (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def pid
  @pid
end

#rssObject (readonly)

Returns the value of attribute rss.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def rss
  @rss
end

#statObject (readonly)

Returns the value of attribute stat.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def stat
  @stat
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def time
  @time
end

#ttyObject (readonly)

Returns the value of attribute tty.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def tty
  @tty
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def user
  @user
end

#vszObject (readonly)

Returns the value of attribute vsz.



5
6
7
# File 'lib/jah/commands/prok.rb', line 5

def vsz
  @vsz
end

Class Method Details

.allObject



14
15
16
17
18
# File 'lib/jah/commands/prok.rb', line 14

def self.all
  `ps auxww`.to_a[1..-1].map do |l|
    new(l.split)
  end
end

.find(comm_or_pid) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/jah/commands/prok.rb', line 20

def self.find(comm_or_pid)
  all.select do |p|
    unless comm_or_pid.to_i.zero?
      p.pid == comm_or_pid.to_i
    else
      p.comm =~ /#{comm_or_pid}/
    end
  end
end

.genocide!(ary) ⇒ Object



56
57
58
59
60
61
# File 'lib/jah/commands/prok.rb', line 56

def self.genocide!(ary)
  parsed = ary.gsub(/\W/, "").split(" ")
  for prok in parsed
    find(prok).each(&:kill!)
  end
end

.read(find = nil) ⇒ Object



9
10
11
12
# File 'lib/jah/commands/prok.rb', line 9

def self.read(find = nil)
  find ? Prok.find(find).to_s : Prok.all.map(&:to_s)

end

Instance Method Details

#hup!Object



40
41
42
# File 'lib/jah/commands/prok.rb', line 40

def hup!
  exec "kill -1 #{pid}"
end

#kill!Object



44
45
46
# File 'lib/jah/commands/prok.rb', line 44

def kill!
  exec "kill #{pid}"
end

#move_to_acre!Object



48
49
50
# File 'lib/jah/commands/prok.rb', line 48

def move_to_acre!
  exec "kill -9 #{pid}"
end

#to_sObject



52
53
54
# File 'lib/jah/commands/prok.rb', line 52

def to_s
  "#{pid} - #{user} - #{comm} (#{mem}, #{cpu})"
end