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>
  • Loading branch information
sam-github committed Nov 15, 2017
1 parent b0d675d commit 515f415
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 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
12 changes: 12 additions & 0 deletions test/parallel/test-process-kill-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ common.expectsError(() => process.kill(1, 'test'), {
message: 'Unknown signal: test'
});

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

// Test kill argument processing in valid cases.
//
// Monkey patch _kill so that we don't actually send any signals, particularly
Expand Down Expand Up @@ -95,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 515f415

Please sign in to comment.