Class: Chukan::LocalProcess

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

Direct Known Subclasses

RemoteProcess

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cmdlineObject (readonly)

Returns the value of attribute cmdline.



129
130
131
# File 'lib/chukan.rb', line 129

def cmdline
  @cmdline
end

#pidObject (readonly)

Returns the value of attribute pid.



131
132
133
# File 'lib/chukan.rb', line 131

def pid
  @pid
end

#statusObject (readonly)

Returns the value of attribute status.



132
133
134
# File 'lib/chukan.rb', line 132

def status
  @status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



130
131
132
# File 'lib/chukan.rb', line 130

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



130
131
132
# File 'lib/chukan.rb', line 130

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



130
131
132
# File 'lib/chukan.rb', line 130

def stdout
  @stdout
end

Instance Method Details

#hupObject



168
169
170
# File 'lib/chukan.rb', line 168

def hup
	signal(:SIGHUP)
end

#joinObject



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

#killObject



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

#termObject



164
165
166
# File 'lib/chukan.rb', line 164

def term
	signal(:SIGTERM)
end