Class: UnixPs::UnixProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/unix-ps/unix_process.rb

Overview

Class that represents a unix process’ basic information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns) ⇒ UnixProcess

Returns a new instance of UnixProcess.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/unix-ps/unix_process.rb', line 9

def initialize(columns)
  # Assign the columns
  @user = columns[0]
  @pid = columns[1].to_i
  @cpu = columns[2].to_f
  @mem = columns[3].to_f
  @vsz = columns[4]
  @rss = columns[5]
  @tty = columns[6]
  @stat = columns[7]
  @start = Time.parse(columns[8])
  @time = columns[9]
  @command = columns[10]
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def command
  @command
end

#cpuObject

Returns the value of attribute cpu.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def cpu
  @cpu
end

#memObject

Returns the value of attribute mem.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def mem
  @mem
end

#pidObject

Returns the value of attribute pid.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def pid
  @pid
end

#rssObject

Returns the value of attribute rss.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def rss
  @rss
end

#startObject

Returns the value of attribute start.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def start
  @start
end

#statObject

Returns the value of attribute stat.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def stat
  @stat
end

#timeObject

Returns the value of attribute time.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def time
  @time
end

#ttyObject

Returns the value of attribute tty.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def tty
  @tty
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def user
  @user
end

#vszObject

Returns the value of attribute vsz.



7
8
9
# File 'lib/unix-ps/unix_process.rb', line 7

def vsz
  @vsz
end

Instance Method Details

#kill!(sig = nil) ⇒ Object

Kill a process



25
26
27
28
# File 'lib/unix-ps/unix_process.rb', line 25

def kill!(sig=nil)
  sig ||= 'INT'
  Process.kill(sig, self.pid)
end