Skip to content

Commit

Permalink
lib: allow process kill by signal number
Browse files Browse the repository at this point in the history
This brings the behaviour in line with the documentation.

PR-URL: #16944
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
sam-github authored and MylesBorins committed Feb 21, 2018
1 parent d73f214 commit 741e82e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ function setupKillAndExit() {
}

// preserve null signal
if (0 === sig) {
err = process._kill(pid, 0);
if (sig === (sig | 0)) {
err = process._kill(pid, sig);
} else {
sig = sig || 'SIGTERM';
if (constants[sig]) {
Expand Down
18 changes: 13 additions & 5 deletions test/parallel/test-process-kill-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ assert.throws(function() { process.kill(1 / 0); },
assert.throws(function() { process.kill(-1 / 0); },
invalidPidArgument);

// Test that kill throws an error for invalid signal
const unknownSignal = common.expectsError({
// Test that kill throws an error for unknown signal names
common.expectsError(() => process.kill(0, 'test'), {
code: 'ERR_UNKNOWN_SIGNAL',
type: TypeError,
message: 'Unknown signal: test'
});


assert.throws(function() { process.kill(1, 'test'); },
unknownSignal);
// Test that kill throws an error for invalid signal numbers
common.expectsError(() => process.kill(0, 987), {
code: 'EINVAL',
type: Error,
message: 'kill EINVAL'
});

// Test kill argument processing in valid cases.
//
Expand Down Expand Up @@ -99,6 +102,11 @@ kill(0, undefined, 0, 15);
kill('0', 'SIGHUP', 0, 1);
kill('0', undefined, 0, 15);

// Confirm that numeric signal arguments are supported

kill(0, 1, 0, 1);
kill(0, 15, 0, 15);

// negative numbers are meaningful on unix
kill(-1, 'SIGHUP', -1, 1);
kill(-1, undefined, -1, 15);
Expand Down

0 comments on commit 741e82e

Please sign in to comment.