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

src: fix kill signal on Windows #55514

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1698,8 +1698,8 @@ may not actually terminate the process.
See kill(2) for reference.
On Windows, where POSIX signals do not exist, the `signal` argument will be
ignored, and the process will be killed forcefully and abruptly (similar to
`'SIGKILL'`).
ignored except `'SIGKILL'`, `'SIGTERM'`, `'SIGINT'` and `'SIGQUIT'`, and the
process will be killed forcefully and abruptly (similar to `'SIGKILL'`).
huseyinacacak-janea marked this conversation as resolved.
Show resolved Hide resolved
See [Signal Events][] for more details.
On Linux, child processes of child processes will not be terminated
Expand Down
6 changes: 6 additions & 0 deletions src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ class ProcessWrap : public HandleWrap {
ProcessWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This());
int signal = args[0]->Int32Value(env->context()).FromJust();
#ifdef _WIN32
if (signal != SIGKILL && signal != SIGTERM && signal != SIGINT &&
signal != SIGQUIT) {
signal = SIGKILL;
}
#endif
int err = uv_process_kill(&wrap->process_, signal);
args.GetReturnValue().Set(err);
}
Expand Down
38 changes: 38 additions & 0 deletions test/parallel/test-child-process-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,41 @@ assert.strictEqual(cat.signalCode, null);
assert.strictEqual(cat.killed, false);
cat.kill();
assert.strictEqual(cat.killed, true);

/* Test different types of kill signals on Windows */
huseyinacacak-janea marked this conversation as resolved.
Show resolved Hide resolved
if (common.isWindows) {
const process1 = spawn('cmd');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be simplified down to a for loop of test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. Fixed it.

process1.on('exit', (code, signal) => {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGTERM');
});
process1.kill('SIGTERM');

const process2 = spawn('cmd');
process2.on('exit', (code, signal) => {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGKILL');
});
process2.kill('SIGKILL');

const process3 = spawn('cmd');
process3.on('exit', (code, signal) => {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGQUIT');
});
process3.kill('SIGQUIT');

const process4 = spawn('cmd');
process4.on('exit', (code, signal) => {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGINT');
});
process4.kill('SIGINT');

const process5 = spawn('cmd');
process5.on('exit', (code, signal) => {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGKILL');
});
process5.kill('SIGHUP');
}
Loading