Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: allow process kill by signal number #16944

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/process.js
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
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