GeezerVison is showing github.com — src: fix kill signal on Windows · nodejs/node@a882536
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/child_process.md +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1700,8 +1700,8 @@ may not actually terminate the process. | 1700 | 1700 | See kill(2) for reference. | 1701 | 1701 |
| 1702 | 1702 | On Windows, where POSIX signals do not exist, the `signal` argument will be | 1703 | | -ignored, and the process will be killed forcefully and abruptly (similar to | 1704 | | -`'SIGKILL'`). | | 1703 | +ignored except for `'SIGKILL'`, `'SIGTERM'`, `'SIGINT'` and `'SIGQUIT'`, and the | | 1704 | +process will always be killed forcefully and abruptly (similar to `'SIGKILL'`). | 1705 | 1705 | See [Signal Events][] for more details. | 1706 | 1706 |
| 1707 | 1707 | On Linux, child processes of child processes will not be terminated | |
Collapse file Copy file name to clipboardExpand all lines: src/process_wrap.cc +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -312,6 +312,12 @@ class ProcessWrap : public HandleWrap { | 312 | 312 | ProcessWrap* wrap; | 313 | 313 | ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This()); | 314 | 314 | int signal = args[0]->Int32Value(env->context()).FromJust(); | | 315 | +#ifdef _WIN32 | | 316 | + if (signal != SIGKILL && signal != SIGTERM && signal != SIGINT && | | 317 | + signal != SIGQUIT) { | | 318 | + signal = SIGKILL; | | 319 | + } | | 320 | +#endif | 315 | 321 | int err = uv_process_kill(&wrap->process_, signal); | 316 | 322 | args.GetReturnValue().Set(err); | 317 | 323 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-child-process-kill.js +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,3 +39,22 @@ assert.strictEqual(cat.signalCode, null); | 39 | 39 | assert.strictEqual(cat.killed, false); | 40 | 40 | cat.kill(); | 41 | 41 | assert.strictEqual(cat.killed, true); | | 42 | + | | 43 | +// Test different types of kill signals on Windows. | | 44 | +if (common.isWindows) { | | 45 | + for (const sendSignal of ['SIGTERM', 'SIGKILL', 'SIGQUIT', 'SIGINT']) { | | 46 | + const process = spawn('cmd'); | | 47 | + process.on('exit', (code, signal) => { | | 48 | + assert.strictEqual(code, null); | | 49 | + assert.strictEqual(signal, sendSignal); | | 50 | + }); | | 51 | + process.kill(sendSignal); | | 52 | + } | | 53 | + | | 54 | + const process = spawn('cmd'); | | 55 | + process.on('exit', (code, signal) => { | | 56 | + assert.strictEqual(code, null); | | 57 | + assert.strictEqual(signal, 'SIGKILL'); | | 58 | + }); | | 59 | + process.kill('SIGHUP'); | | 60 | +} |
|