Description
(This was originally spotted in puma/puma#1558, thanks @dekellum for great help there.)
With JRuby 9.1.16.0 on Java 8 (on latest macOS), I get this:
$ jruby -e 'raise SignalException, "SIGTERM"' ; echo $?
SignalException: SIGTERM
<main> at -e:1
1
Same with JRuby 1.7 actually:
$ rvm use jruby-1.7.27
[09:59:19] plundberg@ecvaawplun6:~/git/tmp (master)
$ jruby -e 'raise SignalException, "SIGTERM"' ; echo $?
SignalException: SIGTERM
(root) at -e:1
1
However, with MRI 2.5.1 I get this:
$ ruby -e 'raise SignalException, "SIGTERM"' ; echo $?
Terminated: 15
143
...which is indeed the correct value for a SIGTERM
-triggered exit of a process.
As inspired by #5049, I tried another approach also which worked slightly differently:
$ rvm use 2.5.1
Using /Users/plundberg/.rvm/gems/ruby-2.5.1
$ ruby -e "Process.kill('TERM', Process.pid)" ; echo $?
Terminated: 15
143
Here be the surprise: JRuby behaves differently, and even differently than the raise SignalException, "SIGTERM"
scenario.
$ rvm use jruby
Using /Users/plundberg/.rvm/gems/jruby-9.1.16.0
$ ruby -e "Process.kill('TERM', Process.pid)" ; echo $?
0
Exit code 0 is not entirely correct, but it's at least much better than exit code 1 which indicates failure. 😄
Inspired by this Oracle article linked to from the JRuby wiki, I tested with the -Xrs
parameter:
$ rvm use jruby
Using /Users/plundberg/.rvm/gems/jruby-9.1.16.0
$ export JAVA_OPTS=-Xrs
$ ruby -e "Process.kill('TERM', Process.pid)" ; echo $?
Terminated: 15
143
$ ruby -e 'raise SignalException, "SIGTERM"' ; echo $?
SignalException: SIGTERM
<main> at -e:1
1
So that makes the Process.kill
approach work just like MRI, which is good (so we have a decent enough workaround for that.) However, the raise SignalException, 'SIGTERM'
still gives the seemingly incorrect exit code.
Is this by design or is it a bug?