Method: ChildProcess::JRuby::Process#pid

Defined in:
lib/childprocess/jruby/process.rb

#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



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/childprocess/jruby/process.rb', line 51

def pid
  if @process.getClass.getName != "java.lang.UNIXProcess"
    raise NotImplementedError, "pid is only supported by JRuby child processes on Unix"
  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