I’m writing a library that I want to work on both JRuby and MRI. The
purpose of the library is to provide ruby configuration and control
(start/stop) for an embedded server which runs in a separate process.
I’m trying to do this:
pid, sin, sout, serr = popen4(server_command) # from open4 for MRI,
IO.popen4 for JRuby
do stuff with in and out
Process.kill 15, pid
This works fine on MRI, but not on JRuby (testing on 1.5.2 on OS X). On
JRuby, I get Errno::ECHILD on the waitpid2 call. Is there a way to do
what I’m trying to do (start process with control of all streams; send a
signal; then wait until the process exits) in JRuby?
I’ve also considered using ProcessBuilder & Process, but there doesn’t
seem to be a way to initiate a graceful shutdown with Process. There’s
just #destroy (which is apparently signal 9) and no way to get the PID
to use kill. It looks like JRuby has code to extract the PID from a
process (ShellLauncher.getPidFromProcess), but I’m not sure if it is
part of the public API (is it?).
I’d appreciate any advice.