lib/childprocess/jruby/process.rb in childprocess-0.1.6 vs lib/childprocess/jruby/process.rb in childprocess-0.1.7

- old
+ new

@@ -26,9 +26,29 @@ @process.waitFor # no way to actually use the timeout here.. @exit_code = @process.exitValue end + # + # Only supported in JRuby on a Unix operating system, thanks to limitations + # in Java's classes + # + # @return [Fixnum] the pid of the process after it has started + # @raise [NotImplementedError] when trying to access pid on non-Unix platform + # + 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 + private def launch_process(&blk) pb = java.lang.ProcessBuilder.new(@args)