Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
721 views
in Technique[技术] by (71.8m points)

ruby - Running fork(2) from Windows with Cygwin. Possible?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...