Class: Console::Mux::Process
- Includes:
- Events, Log4r
- Defined in:
- lib/console/mux/process.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
-
#cputime ⇒ String
Cputime in.
-
#etime ⇒ String
Elapsed time.
-
#initialize(command, name = nil) ⇒ Process
constructor
A new instance of Process.
-
#ps1(field) ⇒ Object
Capture the output of a single field using the ‘ps’ command.
- #receive_line(line) ⇒ Object
-
#rss ⇒ Integer
Resident size in bytes.
- #running? ⇒ Boolean
- #stop(&block) ⇒ Object
- #to_s ⇒ Object
-
#unbind ⇒ Object
Called by the child handler.
-
#uptime ⇒ Integer
Uptime in seconds.
Methods included from Events
Constructor Details
#initialize(command, name = nil) ⇒ Process
Returns a new instance of Process.
40 41 42 43 44 45 |
# File 'lib/console/mux/process.rb', line 40 def initialize(command, name = nil) @command = command @name = name @logger = Logger["process::#{name}"] || Logger.new("process::#{name}") start end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
34 35 36 |
# File 'lib/console/mux/process.rb', line 34 def command @command end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
34 35 36 |
# File 'lib/console/mux/process.rb', line 34 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/console/mux/process.rb', line 34 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
34 35 36 |
# File 'lib/console/mux/process.rb', line 34 def pid @pid end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
34 35 36 |
# File 'lib/console/mux/process.rb', line 34 def started_at @started_at end |
Instance Method Details
#cputime ⇒ String
Returns cputime in.
100 101 102 |
# File 'lib/console/mux/process.rb', line 100 def cputime ps1('cputime') end |
#etime ⇒ String
Returns elapsed time.
90 91 92 |
# File 'lib/console/mux/process.rb', line 90 def etime ps1('etime') end |
#ps1(field) ⇒ Object
Capture the output of a single field using the ‘ps’ command.
85 86 87 |
# File 'lib/console/mux/process.rb', line 85 def ps1(field) `ps -o #{field}= -p #{pid}`.strip end |
#receive_line(line) ⇒ Object
75 76 77 |
# File 'lib/console/mux/process.rb', line 75 def receive_line(line) logger.info { line } end |
#rss ⇒ Integer
Returns resident size in bytes.
95 96 97 |
# File 'lib/console/mux/process.rb', line 95 def rss ps1('rss').to_i * 1024 end |
#running? ⇒ Boolean
53 54 55 |
# File 'lib/console/mux/process.rb', line 53 def running? @handler != nil end |
#stop(&block) ⇒ Object
47 48 49 50 51 |
# File 'lib/console/mux/process.rb', line 47 def stop(&block) if @handler @handler.detach end end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/console/mux/process.rb', line 61 def to_s "#{command} (#{running? ? pid : 'stopped'})" end |
#unbind ⇒ Object
Called by the child handler
66 67 68 69 70 71 72 73 |
# File 'lib/console/mux/process.rb', line 66 def unbind pid2, status = ::Process.waitpid2(pid, ::Process::WNOHANG) if pid2 on_exit(status) else try_kill(['INT', 'TERM', 'KILL']) end end |
#uptime ⇒ Integer
Returns uptime in seconds.
80 81 82 |
# File 'lib/console/mux/process.rb', line 80 def uptime Time.now.to_i - started_at.to_i end |