Created
June 20, 2012 14:38
-
-
Save squarefeet/2960203 to your computer and use it in GitHub Desktop.
Node PID bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
my child.js is this:
var http = require('http');
var server = http.createServer();
server.listen();
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.
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
Something is going awry in my other Node files, then... this test is telling me it's all okay. Fucknuts.