Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix child_process.kill oddities

* Failure should be reported by throwing, like process.kill().
* `exec`-ed processes should not blow up when, upon reaching time /
  buffer limit, an attempt is made to kill them, and this kill fails
  because the process already exited.
* Document this behaviour.

Fixes: #3409
  • Loading branch information...
piscisaureus committed Jun 12, 2012
1 parent a55faea commit 486a5b359019ae8fde044317e35774800b549560
Showing with 15 additions and 8 deletions.
  1. +8 −2 doc/api/child_process.markdown
  2. +7 −6 lib/child_process.js
@@ -119,8 +119,14 @@ be sent `'SIGTERM'`. See `signal(7)` for a list of available signals.
// send SIGHUP to process
grep.kill('SIGHUP');

Note that while the function is called `kill`, the signal delivered to the child
process may not actually kill it. `kill` really just sends a signal to a process.
Although the function is called `kill`, the signal delivered to the child
process may not actually kill it. `kill` really just sends a signal to a
process.

Also note that if the child process already exited when `kill` is called,
an exception will be thrown. This can even happen when the `child_process`
object did not emit `exit yet. Therefore it is wise to wrap the `kill` call in

This comment has been minimized.

Copy link
@isaacs

isaacs Jun 12, 2012

s/exit/exit/` (missing the closing tick.)

a try..catch block.
See `kill(2)`

@@ -538,10 +538,12 @@ exports.execFile = function(file /* args, options, callback */) {

function kill() {
killed = true;
child.kill(options.killSignal);
process.nextTick(function() {
exithandler(null, options.killSignal);
});
try {
child.kill(options.killSignal);
} catch (e) {
}
child.stdout.destroy();
child.stderr.destroy();
}

if (options.timeout > 0) {
@@ -837,8 +839,7 @@ ChildProcess.prototype.kill = function(sig) {
this.killed = true;
var r = this._handle.kill(signal);
if (r === -1) {
this.emit('error', errnoException(errno, 'kill'));
return;
throw errnoException(errno, 'kill');
}
}
};

0 comments on commit 486a5b3

Please sign in to comment.
You can’t perform that action at this time.