Skip to content

Commit 1fc0a41

Browse 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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 72484e5 commit 1fc0a41

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

‎lib/internal/process.js‎

Lines 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]){

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

Lines 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-
constunknownSignal=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)