Running fork(2) from Windows with Cygwin. Possible?
Asked Answered
Q

1

5

I am trying to use a Ruby gem called shotgun that requires fork(2) command which I discovered is aa Linux command, and might be available in Cygwin. Is it possible to make it available through Windows command shell?

Quinby answered 29/11, 2009 at 7:25 Comment(0)
S
7

fork(2) is kludgey under Cygwin, as the Windows process model does not easily allow it to happen. Cygwin may allow its spawn to use it, but you're going to suffer a serious performance hit as Cygwin has to emulate everything by hand -- including copying the executable data, copying the open handles, etc.

Depending on how much shotgun uses fork(2), this emulation could be painful or it could be relatively minor.

Here's a good thread on GameDev.net discussing the lack of a fork facility on Win32. They bring up something which I don't have the patience or platform accessibility to investigate, but certainly sounds fun, dangerous, and explosive all at the same time:

So, you need to bypass Win32 and call the native API ({Nt|Zw}CreateProcess). The book "Windows Nt/2000 Native Api Reference" has an example "Forking a Win32 Process". This may be what you need.

I'm intrigued, but I doubt Cygwin uses it. It's probably there, to reiterate my answer to your question -- a lot of Unix apps rely on fork, and Cygwin likely makes it available. Just don't expect miracles, and you'll have to make Ruby aware of Cygwin by recompiling it to include its emulation layer.

Satyr answered 29/11, 2009 at 8:8 Comment(1)
Great reply! I will try recompiling Ruby with the Cygwin emulation layer tomorrow. If it works, that would be awesome; some performance hit would be ok. The other path sounds risky, and it would require lots of hacking...but it's good to know what's possible. Many thanks!Quinby

© 2022 - 2024 — McMap. All rights reserved.