node --version => v4.1.2
uname -a => Darwin xxx 15.0.0 Darwin Kernel Version 15.0.0: Wed Aug 26 16:57:32 PDT 2015; root:xnu-3247.1.106~1/RELEASE_X86_64 x86_64
only the last spawned child_process instance will get the emitted 'exit' and 'close' events, but this also for OTHER instances too...
100% reproducable with this source:
var child_process = require('child_process');
ChildProcess = function(description, executable, arguments, callback) {
this.description = description;
this.exited = false;
this.process = child_process.spawn(executable, arguments);
self = this;
this.process.on('exit', function(code, signal) {
self.exited = true;
console.log(self.description + " process.on:exit", code, signal);
}).on('close', function(code, signal) {
self.exited = true;
console.log(self.description + " process.on:close", code, signal);
if (callback) callback(code, signal);
}).on('error', function(err) {
console.log(self.description + " process.on:error", err);
});
}
ChildProcess.prototype.kill = function(signal) {
if (this.exited) return;
console.log(this.description + " .kill", signal);
this.process.kill(signal);
}
p1 = new ChildProcess("p1", "/bin/sleep", [ "11" ], function(code, signal) {
console.log("p1 <= ", code, signal);
});
p2 = new ChildProcess("p2", "/bin/sleep", [ "12" ], function(code, signal) {
console.log("p2 <= ", code, signal);
});
setTimeout(function() {
p2.kill("SIGTERM");
p1.kill("SIGTERM");
}, 1000);
Output is
p2 .kill SIGTERM
p1 .kill SIGTERM
p2 process.on:exit null SIGTERM
p2 process.on:exit null SIGTERM
p2 process.on:close null SIGTERM
p2 <= null SIGTERM
p2 process.on:close null SIGTERM
p1 <= null SIGTERM
node --version => v4.1.2
uname -a => Darwin xxx 15.0.0 Darwin Kernel Version 15.0.0: Wed Aug 26 16:57:32 PDT 2015; root:xnu-3247.1.106~1/RELEASE_X86_64 x86_64
only the last spawned child_process instance will get the emitted 'exit' and 'close' events, but this also for OTHER instances too...
100% reproducable with this source:
Output is