Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong>: There is one common use case of <code>fork()</code> that can be replaced with <code>spawn()</code> -- the <code>fork()</code>--<code>exec()</code> combo. A lot of older (and modern) UNIX applications, when they want to spawn another process, will first fork, and then make an <code>exec</code> call (<code>exec</code> replaces the current process with another). This doesn't actually need <code>fork()</code>, which is why it can be replaced with <code>spawn()</code>. So, this:</p> <pre><code>if(!fork()) exec("dir") end </code></pre> <p>can be replaced with:</p> <pre><code>Process.spawn("dir") </code></pre> <p>If any of the gems are using <code>fork()</code> like this, the fix is easy. Otherwise, it is almost impossible. </p> <hr> <p><strong>EDIT</strong>: The reason why win32-process' implementation of <code>fork()</code> doesn't work is that (as far as I can tell from the docs), it basically <em>is</em> <code>spawn()</code>, which isn't <code>fork()</code> at all. </p> <hr> <p>No, I don't think it can be done. You see, <code>Process.spawn</code> creates a new process with the default blank state and native code. So, while I can do something like <code>Process.spawn('dir')</code> will start a <em>new</em>, <em>blank</em> process running <code>dir</code>, it won't clone <em>any</em> of the current process' state. It's only connection to your program is the parent - child connection.</p> <p>You see, <code>fork()</code> is a very low level call. For example, on Linux, what <code>fork()</code> basically does is this: first, a new process is created with <em>exactly</em> cloned register state. Then, Linux does a copy-on-write reference to all of the parent process' pages. Linux then clones some other process flags. Obviously, all of these operations can only be done by the kernel, and the Windows kernel doesn't have the facilities to do that (and can't be patched to either). </p> <p>Technically, only native programs need the OS for some sort of <code>fork()</code>-like support. Any layer of code needs the cooperation of the layer above it to do something like <code>fork()</code>. So while native C code needs the cooperation of the kernel to fork, Ruby theoretically only needs the cooperation of the interpreter to do a fork. However, the Ruby interpreter does not have a snapshot/restore feature, which would be necessarily to implement a fork. Because of this, normal Ruby fork is achieved by forking the interpreter itself, not the Ruby program. </p> <p>So, while if you could patch the Ruby interpreter to add a stop/start and snapshot/restore feature, you could do it, but otherwise? I don't think so.</p> <p>So what are your options? This is what I can think of:</p> <ul> <li>Patch the Ruby interpreter</li> <li>Patch the code that uses <code>fork()</code> to maybe use threads or spawn</li> <li>Get a UNIX (I suggest this one)</li> <li>Use Cygwin</li> </ul> <p>Edit 1: I wouldn't suggest using Cygwin's fork, as it involves special Cygwin process tables, there is <strong>no</strong> copy-on-write, which makes it very inefficient. Also, it involves a lot of jumping back and forth and a lot of copying. Avoid it if possible. Also, because Windows provides no facilities to copy address spaces, forks are very likely to fail, and will quite a lot of the time (see <a href="http://cygwin.com/cygwin-ug-net/highlights.html" rel="noreferrer">here</a>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload