Class: Chukan::LocalProcess
- Inherits:
-
Object
- Object
- Chukan::LocalProcess
- Defined in:
- lib/chukan.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cmdline ⇒ Object
readonly
Returns the value of attribute cmdline.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #hup ⇒ Object
-
#initialize(*cmdline) ⇒ LocalProcess
constructor
A new instance of LocalProcess.
- #join ⇒ Object
- #kill ⇒ Object
- #set_display(shortname) ⇒ Object
- #signal(sig) ⇒ Object
- #stderr_join(pattern, &block) ⇒ Object
- #stdout_join(pattern, &block) ⇒ Object
- #term ⇒ Object
Constructor Details
#initialize(*cmdline) ⇒ LocalProcess
Returns a new instance of LocalProcess.
120 121 122 123 124 125 126 127 |
# File 'lib/chukan.rb', line 120 def initialize(*cmdline) @cmdline = cmdline.map {|x| x.to_s } @status = nil @shortname = cmdline.join(' ').split(/\s/) @shortname[0] = File.basename(@shortname[0]) @shortname = @shortname.join(' ')[0, 12] start end |
Instance Attribute Details
#cmdline ⇒ Object (readonly)
Returns the value of attribute cmdline.
129 130 131 |
# File 'lib/chukan.rb', line 129 def cmdline @cmdline end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
131 132 133 |
# File 'lib/chukan.rb', line 131 def pid @pid end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
132 133 134 |
# File 'lib/chukan.rb', line 132 def status @status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
130 131 132 |
# File 'lib/chukan.rb', line 130 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
130 131 132 |
# File 'lib/chukan.rb', line 130 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
130 131 132 |
# File 'lib/chukan.rb', line 130 def stdout @stdout end |
Instance Method Details
#hup ⇒ Object
168 169 170 |
# File 'lib/chukan.rb', line 168 def hup signal(:SIGHUP) end |
#join ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/chukan.rb', line 134 def join @status = Process.waitpid2(@pid)[1] @stdout_reader.join @stderr_reader.join @killer.killed reason = @status.inspect if m = reason.match(/\,([^\>]*)\>/) reason = m[1] end $stderr.puts "#{@msg_prefix}#{reason}" @status end |
#kill ⇒ Object
160 161 162 |
# File 'lib/chukan.rb', line 160 def kill signal(:SIGKILL) end |
#set_display(shortname) ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/chukan.rb', line 172 def set_display(shortname) if shortname.length <= 12 @msg_prefix[0..-1] = "[%-12s %6d] " % [shortname, @pid] elsif shortname.length < 19 @msg_prefix[0..-1] = "[%-19s] " % [shortname] else @msg_prefix[0..-1] = "[#{shortname}] " end self end |
#signal(sig) ⇒ Object
155 156 157 158 |
# File 'lib/chukan.rb', line 155 def signal(sig) Process.kill(sig, @pid) rescue nil self end |
#stderr_join(pattern, &block) ⇒ Object
151 152 153 |
# File 'lib/chukan.rb', line 151 def stderr_join(pattern, &block) io_join(@stderr, pattern, &block) end |
#stdout_join(pattern, &block) ⇒ Object
147 148 149 |
# File 'lib/chukan.rb', line 147 def stdout_join(pattern, &block) io_join(@stdout, pattern, &block) end |
#term ⇒ Object
164 165 166 |
# File 'lib/chukan.rb', line 164 def term signal(:SIGTERM) end |