Groking system() on Windows

I’m trying to use system() from JRuby 1.6.0.RC1 on Windows to integrate
with Process Monitor [1] to do some WinAPI tracing for performance
comparisons. The actual code lives at [2] but I’ve got a test case that
shows the issue at figuring out MRI and JRuby's use of system() · GitHub

Basically, I want to start up procmon.exe and immediately return. Call
procmon again and tell it to wait. Fire up JRuby to run some code (line
24) to be traced by procmon and return when the test code completes.
After that’s all done, tell procmon to terminate.

Charlie has either blogged or posted to ruby-core on calling
jruby-from-jruby and, IIRC, the punchline is that JRuby does some
optimizations so that things run in the same JRuby process. The problem
I’m having is that it appears that line 24 in the gist never returns
from the system() call and I’m guessing the reason is that it was run in
the existing JRuby process.

While the MRI and JRuby behavior is different (appears to hang on JRuby)
I just want to understand JRuby’s behavior better and find a better
solution than the one I’m currently using to trace how the different
impl’s use WinAPI calls to do things like read large files line-by-line
and other things.

A working case on MRI looks like…

C:\Users\Jon\Documents\RubyDev\sandbox>ruby system_ruby.rb
[INFO] doing some work via system()…
ruby 1.9.2p174 (2011-01-28 revision 30696) [i386-mingw32]
[INFO] OK, I’m back.
[INFO] playing with processes via system()…
ruby 1.9.2p174 (2011-01-28 revision 30696) [i386-mingw32]
[INFO] OK, I’m back.

…and the failing case on JRuby looks like…

C:\Users\Jon\Documents\RubyDev\sandbox>jruby system_ruby.rb
[INFO] doing some work via system()…
jruby 1.6.0.RC1 (ruby 1.9.2 trunk 136) (2011-01-10 769f847) (Java
HotSpot™ Client
VM 1.6.0_23) [Windows 7-x86-java]
[INFO] OK, I’m back.
[INFO] playing with processes via system()…

[1] Process Monitor - Sysinternals | Microsoft Learn
[2]
http://github.com/jonforums/measurements/blob/master/lib/tracers/processmonitor.rb

Jon


blog: http://jonforums.github.com/
twitter: @jonforums

jruby.launch.inproc=false might help

setting jruby.launch.inproc property to false help?

setting jruby.launch.inproc property to false help?

Thanks Roger…will give it a try…forgot about that one :frowning:

Jon


blog: http://jonforums.github.com/
twitter: @jonforums

setting jruby.launch.inproc property to false help?

Thanks Roger…will give it a try…forgot about that one :frowning:

Updated figuring out MRI and JRuby's use of system() · GitHub and run via jruby
-Xlaunch.inproc=false system_ruby.rb but that doesn’t fix things.

On 1.6.0.RC1 in 1.9 mode, the issue is not where I thought it was. It’s
the first system() call with “start…” (line 23) that never returns
(MRI’s system(“start…”) does return) as this shows:

C:\Users\Jon\Documents\RubyDev\sandbox>jruby -Xlaunch.inproc=false
system_ruby.rb
[INFO] doing some work via system()…
jruby 1.6.0.RC1 (ruby 1.9.2 trunk 136) (2011-01-10 769f847) (Java
HotSpot™ Cli
VM 1.6.0_23) [Windows 7-x86-java]
[INFO] OK, I’m back from the working case.
[INFO] playing with processes via system()…
[INFO] starting 1st system

I’m checking in 1.8 mode and on 1.5.6 to see if JRuby’s
system(“start…”) behaves differently.

Jon


blog: http://jonforums.github.com/
twitter: @jonforums

Updated figuring out MRI and JRuby's use of system() · GitHub and run via jruby
-Xlaunch.inproc=false system_ruby.rb but that doesn’t fix things.

I assume that’s equivalent to starting it like

-J-Djruby.launch.inproc=false
?
-r

[INFO] OK, I’m back from the working case.
[INFO] playing with processes via system()…
[INFO] starting 1st system

I’m checking in 1.8 mode and on 1.5.6 to see if JRuby’s system(“start…”)
behaves differently.

Tried the above snippet figuring out MRI and JRuby's use of system() · GitHub with 1.6.0.RC2
and 1.5.6 in both 1.8 and 1.9 modes…works on MRI Ruby and fails on
JRuby as shown above.

Roger…have you tried the gist on your RC2 using the following and have
it working?

jruby --1.9 -Xlaunch.inproc=false system_ruby.rb
jruby -Xlaunch.inproc=false system_ruby.rb

Jon


blog: http://jonforums.github.com/
twitter: @jonforums

looks like a bug:

system(“start ruby.exe -e sleep”)

returns immediately in windows, but “waits” in jruby, for some reason.

I’d file a JIRA for it :slight_smile:

I agree and will file a JIRA later this morning. Thanks for
reproducing…what Windows version?

FWIW, a more relevant quick test is

jruby --1.9 -Xlaunch.inproc=false -ve “system(‘start dxdiag.exe’)”

In the meantime, ffi might help.

FFI wrapper for CreateProcess() · GitHub

Interesting, thanks for the pointer as I’m a fan of FFI. However, it’s
an unwelcome dependency for what I’m trying to do.

I’d rather have this Windows bug fixed in 1.6.0, or find a usable
workaround.

Jon


blog: http://jonforums.github.com/
twitter: @jonforums

looks like a bug:

system(“start ruby.exe -e sleep”)

returns immediately in windows, but “waits” in jruby, for some reason.

I’d file a JIRA for it :slight_smile:

In the meantime, ffi might help.

-r

Interesting, thanks for the pointer as I’m a fan of FFI. However, it’s
an unwelcome dependency for what I’m trying to do.

I’d rather have this Windows bug fixed in 1.6.0, or find a usable
workaround.

IO.popen?
I guess ffi is bundled with jruby but not with MRI.
-r

http://jira.codehaus.org/browse/JRUBY-5493

IO.popen?

Next on the to-look-at list in case this can’t be resolved for 1.6.0 and
as a workaround for 1.5.6.

Jon


blog: http://jonforums.github.com/
twitter: @jonforums