[Rubygems-developers] Problems managing embedded gem server on Windows

Chad Woolley thewoolleyman at gmail.com
Sun Jan 14 03:13:49 EST 2007


I have an open source project where I run an "embedded" gem_server for
self-contained testing purposes.  This means I spawn a "gem_server"
executable via ruby, then kill it via the PID when my tests are done.

The problem is that I can't seem to avoid leaving an orphaned ruby
process when I run this on windows.

This is due to several reasons:

* gem_server on windows is implemented as a batch file
(gem_server.bat) with inline ruby.  There is no separate
"gem_server.rb" class that I could invoke programatically and solve
the whole problem.

* On Windows, this causes a tree of child processes to be created:
cmd  (shell that I invoke my tests from) -> ruby (my tests) -> cmd
(the batch file) -> ruby (the inline ruby process spawned by the batch

* I cannot figure out a way to kill the inlined ruby process.  I can
grab the PID of the batch file cmd process itself, but when I kill
that, windows just orphans the ruby process.

* Since the gem server ruby process spawned by the batch file is a
*DAEMON* (never dies), I don't think I can use fork/wait or any of the
other fancy stuff in win32-open3, win32-process, etc.

Any ideas on how to get around this?  Am I missing some magic
incantation to kill a child daemon process for which I only have the
parent's PID?

One solution would be to extract the inlined ruby code in
gem_server.bat to a real ruby class in a separate file.  Then, I could
call it programatically and not worry about the intervening cmd shell
in the process hierarchy.  What do you think about this?

-- Chad W

More information about the Rubygems-developers mailing list