From: "Jörg W Mittag" Date: 2010-09-01T20:05:07+09:00 Subject: Re: fork() function is unimplemented on this machine Ralph Shnelvar wrote: > I am trying to implement the code on page 181 of *Programming Ruby 1.9* > > The code on that page reads > > - - - > trap("CLD") do > pid = Process.wait > puts "Child pid #{pid}: terminated > end > fork { exec("sort testfile >output.txt") } > - - - > > When I attempt to run similar code I first get that > unsupported signal SIGCLD > > I tried SIGCHLD ... same problem. > > Signals.list generates > {"SEGV"=>11, "KILL"=>9, "TERM"=>15, "INT"=>2, "FPE"=>8, "ABRT"=>22, "ILL"=>4, "EXIT"=>0} > > So I next tried > > - - - > trap("EXIT") do > pid = Process.wait > puts "Child pid #{pid}: terminated > end > fork { exec("sort testfile >output.txt") } > - - - > > and that's when I get the msg > fork() function is unimplemented on this machine > > Is fork truly not implemented for 1.8.6 and Windows? fork is a POSIX/Unix system call. It is therefore only available on POSIX/Unix. This does not only apply to Ruby 1.8.6, but to all versions of Ruby, and it not only applies to Windows, but to all non-POSIX platforms including, for example, the JVM, the CLI, the Flash VM or ECMAScript. This surprised me (and still does) and I would consider this a bug, but I saw a video of an interview with Yukihiro Matsumoto in which he explained that this is in fact not a bug but a feature. Ruby is deliberately *not* intended to be platform-independent, and the fact that Ruby programs behave differently or don't work *at all* when run on a different operating system or even on the same operating system and a different CPU is normal and expected. Note: there are POSIX emulation layers for Windows, such as Cygwin or Microsoft's own Services for Unix. However, you will need to build your execution engine specifically for those platforms if you want to use them. Also, this doesn't change the fact that processes in Windows are used for completely different purposes than processes on Unix, and thus have substantially different performance characteristics and behaviors. [...] > here are the various signals for ruby documented? Again: those are POSIX signals. Which signals are available on which platform depends on the platform, so you have to look in your platform's manual instead of Ruby's. In this particular case, I assume you are using the MinGW port of the MRI Ruby execution engine, so you will find a list of the supported signals in the MinGW documentation. (Actually, you probably won't, since their documentation isn't particularly good. You'll probably have to look through the source code.) In particular, the SIGCHILD signal is related to POSIX's process model, which doesn't really apply on Windows. jwm