Class: ChildProcess::JRuby::Process

Inherits:
AbstractProcess show all
Defined in:
lib/childprocess/jruby/process.rb

Constant Summary

Constants inherited from AbstractProcess

AbstractProcess::POLL_INTERVAL

Instance Attribute Summary

Attributes inherited from AbstractProcess

#detach, #duplex, #environment, #exit_code

Instance Method Summary collapse

Methods inherited from AbstractProcess

#alive?, #crashed?, #initialize, #poll_for_exit, #start

Constructor Details

This class inherits a constructor from ChildProcess::AbstractProcess

Instance Method Details

#exited?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/childprocess/jruby/process.rb', line 10

def exited?
  return true if @exit_code

  assert_started
  @exit_code = @process.exitValue
  true
rescue java.lang.IllegalThreadStateException
  false
ensure
  log(:exit_code => @exit_code)
end

#ioObject



6
7
8
# File 'lib/childprocess/jruby/process.rb', line 6

def io
  @io ||= JRuby::IO.new
end

#pidFixnum

Only supported in JRuby on a Unix operating system, thanks to limitations in Java’s classes

Returns:

  • (Fixnum)

    the pid of the process after it has started

Raises:

  • (NotImplementedError)

    when trying to access pid on non-Unix platform



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/childprocess/jruby/process.rb', line 38

def pid
  if @process.getClass.getName != "java.lang.UNIXProcess"
    raise NotImplementedError.new("pid is not supported by JRuby child processes on Windows")
  end

  # About the best way we can do this is with a nasty reflection-based impl
  # Thanks to Martijn Courteaux
  # http://stackoverflow.com/questions/2950338/how-can-i-kill-a-linux-process-in-java-with-sigkill-process-destroy-does-sigter/2951193#2951193
  field = @process.getClass.getDeclaredField("pid")
  field.accessible = true
  field.get(@process)
end

#stop(timeout = nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/childprocess/jruby/process.rb', line 22

def stop(timeout = nil)
  assert_started

  @process.destroy
  @process.waitFor # no way to actually use the timeout here..

  @exit_code = @process.exitValue
end