[jruby-user] Groking system() on Windows

11 views
Skip to first unread message

Jon

unread,
Feb 4, 2011, 4:24:33 PM2/4/11
to us...@jruby.codehaus.org
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 https://gist.github.com/811728

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(TM) Client
VM 1.6.0_23) [Windows 7-x86-java]
[INFO] OK, I'm back.
[INFO] playing with processes via system()...


[1] http://technet.microsoft.com/en-us/sysinternals/bb896645
[2] http://github.com/jonforums/measurements/blob/master/lib/tracers/processmonitor.rb


Jon

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

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Roger Pack

unread,
Feb 5, 2011, 2:10:47 AM2/5/11
to us...@jruby.codehaus.org
jruby.launch.inproc=false might help

--
Posted via http://www.ruby-forum.com/.

Roger Pack

unread,
Feb 5, 2011, 2:13:23 AM2/5/11
to us...@jruby.codehaus.org
setting jruby.launch.inproc property to false help?

---------------------------------------------------------------------

Jon

unread,
Feb 5, 2011, 10:40:15 AM2/5/11
to us...@jruby.codehaus.org
> setting jruby.launch.inproc property to false help?

Thanks Roger...will give it a try...forgot about that one :(

Jon

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

---------------------------------------------------------------------

Jon

unread,
Feb 5, 2011, 1:23:10 PM2/5/11
to us...@jruby.codehaus.org
> > setting jruby.launch.inproc property to false help?
>
> Thanks Roger...will give it a try...forgot about that one :(

Updated https://gist.github.com/811728 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(TM) 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.

Roger Pack

unread,
Feb 5, 2011, 9:12:09 PM2/5/11
to us...@jruby.codehaus.org
> Updated https://gist.github.com/811728 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

---------------------------------------------------------------------

Jon

unread,
Feb 10, 2011, 3:33:03 PM2/10/11
to us...@jruby.codehaus.org
> > > setting jruby.launch.inproc property to false help?
> >
> Updated https://gist.github.com/811728 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(TM) 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.

Tried the above snippet https://gist.github.com/811728 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

Roger Pack

unread,
Feb 10, 2011, 7:43:28 PM2/10/11
to us...@jruby.codehaus.org
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 :)

In the meantime, ffi might help.

https://gist.github.com/280865

-r

---------------------------------------------------------------------

Jon

unread,
Feb 11, 2011, 9:39:03 AM2/11/11
to us...@jruby.codehaus.org
> 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 :)

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.
>
> https://gist.github.com/280865

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

---------------------------------------------------------------------

Roger Pack

unread,
Feb 11, 2011, 10:16:04 AM2/11/11
to us...@jruby.codehaus.org
> 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

---------------------------------------------------------------------

Jon

unread,
Feb 11, 2011, 11:19:56 AM2/11/11
to us...@jruby.codehaus.org
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

---------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages