Skip to content

src: fix kill signal 0 on Windows #57695

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class ProcessWrap : public HandleWrap {
}
#ifdef _WIN32
if (signal != SIGKILL && signal != SIGTERM && signal != SIGINT &&
signal != SIGQUIT) {
signal != SIGQUIT && signal != 0) {
signal = SIGKILL;
}
#endif
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-child-process-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ if (common.isWindows) {
});
process.kill('SIGHUP');
}

// Test that the process is not killed when sending a 0 signal.
// This is a no-op signal that is used to check if the process is alive.
const code = `const interval = setInterval(() => {}, 1000);
process.stdin.on('data', () => { clearInterval(interval); });
process.stdout.write('x');`;

const checkProcess = spawn(process.execPath, ['-e', code]);

checkProcess.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

checkProcess.stdout.on('data', common.mustCall((chunk) => {
assert.strictEqual(chunk.toString(), 'x');
checkProcess.kill(0);
checkProcess.stdin.write('x');
checkProcess.stdin.end();
}));
Loading