Skip to content

Instantly share code, notes, and snippets.

@squarefeet
Created June 20, 2012 14:38
Show Gist options
  • Save squarefeet/2960203 to your computer and use it in GitHub Desktop.
Save squarefeet/2960203 to your computer and use it in GitHub Desktop.
Node PID bug
var exec = require('child_process').exec,
child = exec('node [PATH-TO-YOUR-KEEP-ALIVE-NODE-FILE]');
console.log('child pid: ' + child.pid);
exec('ps aux | grep node', function(err, stdout) {
console.log(stdout);
});
@squarefeet
Copy link
Author

Mine's very similar:

require('http').createServer().listen(23984);

I'm going to dig deeper and see if it's anything to do with the REPL I'm using.

@squarefeet
Copy link
Author

Think this is the cause:

luke     71743   0.0  0.0  2435116    524 s001  R+    4:05pm   0:00.00 grep node
luke     71733   0.0  0.4  3048568  17616 s000  S+    4:05pm   0:00.31 node test.js
luke     71732   0.0  0.0  2435544    768 s000  S+    4:05pm   0:00.00 /bin/sh -c cd node_modules/grppl-simserver && node test.js
luke     71730   0.0  0.3  3047240  13280 s000  S+    4:05pm   0:00.15 node index.js

See that /bin/sh -c ... line? That's the process that child.pid is reporting back. SIGTERM-ing that process does fuck all. To kill the child process, you need to kill node test.js, which is another process spawned straight after the exec command.

So.. exec creates one process, and 'cos I'm spinning up a new node instance within that exec child proc, it'll have a diff. pid than the exec proc.

Bit of a derp moment :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment