Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1fc0a41

Browse filesBrowse files
sam-githubMylesBorins
authored andcommitted
lib: allow process kill by signal number
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>
1 parent 72484e5 commit 1fc0a41
Copy full SHA for 1fc0a41

File tree

Expand file treeCollapse file tree

2 files changed

+15
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-7
lines changed
Open diff view settings
Collapse file

‎lib/internal/process.js‎

Copy file name to clipboardExpand all lines: lib/internal/process.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ function setupKillAndExit() {
158158
}
159159

160160
// preserve null signal
161-
if (0 === sig) {
162-
err = process._kill(pid, 0);
161+
if (sig === (sig | 0)) {
162+
err = process._kill(pid, sig);
163163
} else {
164164
sig = sig || 'SIGTERM';
165165
if (constants[sig]) {
Collapse file

‎test/parallel/test-process-kill-pid.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-process-kill-pid.js
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ assert.throws(function() { process.kill(1 / 0); },
5757
assert.throws(function() { process.kill(-1 / 0); },
5858
invalidPidArgument);
5959

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

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

7174
// Test kill argument processing in valid cases.
7275
//
@@ -99,6 +102,11 @@ kill(0, undefined, 0, 15);
99102
kill('0', 'SIGHUP', 0, 1);
100103
kill('0', undefined, 0, 15);
101104

105+
// Confirm that numeric signal arguments are supported
106+
107+
kill(0, 1, 0, 1);
108+
kill(0, 15, 0, 15);
109+
102110
// negative numbers are meaningful on unix
103111
kill(-1, 'SIGHUP', -1, 1);
104112
kill(-1, undefined, -1, 15);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.