When I call Kernel.fork()
on Windows, I get t开发者_如何学Gohis error:
!! Unexpected error while processing request: fork() function is unimplemented on this machine
Is there an alternative way to fork while on Windows?
Try spawn()
- it's implemented for windows.
While the Windows OS does not support fork, the win32-process gem appears to support a substitute. Apparently there are some differences from the unix version though, see this question: fork with Ruby 1.8 and Windows
The usual way to get a faithful fork emulation on Windows is to install Cygwin and run with its library. In this case you will need to install a second Ruby, this time from the Cygwin package.
As DigitalRoss mentioned, Cygwin is POSIX compliant, and has fork.
$ irb
irb(main):001:0> Kernel.fork()
=> 4512
irb(main):002:0> => nil
irb(main):002:0> quit
$ uname -a
CYGWIN_NT-5.1 dumbopc 1.7.17(0.262/5/3) 2012-10-19 14:39 i686 Cygwin
$ ruby -v
ruby 1.9.3p385 (2013-02-06 revision 39114) [i386-cygwin]
You may have to use the Cygwin Ports mirror to find the Ruby package.
Windows 10 has the Windows Subsystem for Linux feature that you can install.
https://msdn.microsoft.com/en-us/commandline/wsl/install-win10
This will allow you to leverage one of the Unix Distro apps in the Windows store to install a bash shell. You can then run your app in a Linux environment, effectively enabling Fork()
精彩评论