JRuby, fork, exec and daemons (oh my)

The default setting under JRuby gives a very nice warning when fork is
used. It says that this is “dangerous” and is therefore turned off by
default.

However, Headius just put up a blog post about using FFI in JRuby to
call the system level fork and exec methods. Is this approach less
“dangerous” than the JRuby built in methods? Why exactly is fork
dangerous in JRuby?

Thanks for any insights / answers.

Blessings,
TwP


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Tim P. wrote:

The default setting under JRuby gives a very nice warning when fork is
used. It says that this is “dangerous” and is therefore turned off by
default.

However, Headius just put up a blog post about using FFI in JRuby to
call the system level fork and exec methods. Is this approach less
“dangerous” than the JRuby built in methods? Why exactly is fork
dangerous in JRuby?

fork only brings across the calling thread, and since the JVM out of the
box uses multiple threads for GC, event handling, reference cleanup,
finalization, and so on, the resulting forked JVM won’t live long. Only
if you do a fork + exec can you escape those issues, since you won’t run
more than a tiny bit of code in the forked JVM.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, May 14, 2009 at 5:35 PM, Charles Oliver N.
[email protected] wrote:

fork only brings across the calling thread, and since the JVM out of the box
uses multiple threads for GC, event handling, reference cleanup,
finalization, and so on, the resulting forked JVM won’t live long. Only if
you do a fork + exec can you escape those issues, since you won’t run more
than a tiny bit of code in the forked JVM.

I assume this same logic also applies to the system fork that would
called via FFI, correct?

TwP


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, May 14, 2009 at 6:37 PM, Tim P. [email protected] wrote:

“dangerous” than the JRuby built in methods? Why exactly is fork
called via FFI, correct?

And I just re-read the man pages on fork and pthread_atfork. Answered
my own question – yes, calling fork via FFI only starts the calling
thread in the child process.

Thanks for the post about FFI, though. Got me thinking in some new
directions.

Blessings,
TwP


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Tim P. wrote:

I assume this same logic also applies to the system fork that would
called via FFI, correct?

And I just re-read the man pages on fork and pthread_atfork. Answered
my own question – yes, calling fork via FFI only starts the calling
thread in the child process.

Thanks for the post about FFI, though. Got me thinking in some new directions.

There are certainly a lot of interesting opportunities, though they
obviously will require plenty of care :slight_smile:

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email