title: Reattaching to spawned process via nodejs
body: <p>I am creating a small proprietary game server manager in Node.js; currently it runs the game by spawning via <code>child_process</code>:</p>
  
  <pre><code>var server = spawn(cmd, args, { cwd: 'something' });
  </code></pre>
  
  <p>So long as the manager continues to run I can pipe commands and deal with the child as I would like. However, consider the possibility that my manager crashes or is closed. How would I then <em>reattach</em>  to the previously spawned child process (which was still running while the manager was down)? I can store pidfiles to try and reconnect based on pid; but I'm not sure how to get a <code>child_process</code> object with  access to the child's <code>stdio</code> objects.</p>
  
  <p>I really would like this to be recoverable; any help is appreciated, thanks!</p>
  
  <hr>
  
  <p><strong>Please note</strong>: The game servers are proprietary, some examples are Minecraft, Source DS, etc. Assume i do not have access to the sever source.</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>After reading some source code from node's <code>child_process</code> it looks like if you specify a property in the options called <code>stdinStream</code>, <code>stdoutStream</code>, or <code>stderrStream</code> it should just open a socket to it. (See lines <a href="https://github.com/joyent/node/blob/master/lib/child_process.js#L428" rel="noreferrer">428</a> - <a href="https://github.com/joyent/node/blob/master/lib/child_process.js#L496" rel="noreferrer">496</a>). So the issue then is, how do I stop spawn from <em>actually</em> doing a spawn and instead just settings its values based on a specified pid and streams I pass. (I would get my <code>stdinStream</code> by doing <code>fs.createWriteStream('/proc/PID/fd/0');</code> which should work since that fd is created as a pipe.)</p>