I'm starting a process in a node app, running on Windows, which I cannot kill. I'm using node's exec
which requires a command line parameter (thus I cannot use spawn
). Normally this process runs without ending, expecting a Ctrl+C from the user to end it. I want to instead programmatically end it from within node.
For a simplified example of the scenario:
import { exec } from 'child_process'; // (Note that this is an ESM/module type file)
// Start the process (in this example, it runs a local server)
const serverProcess = exec('cordova run browser --port=1234');
// Wait a bit, and then try to kill the process
setTimeout(() => {
serverProcess.kill();
// also tried: process.kill(serverProcess.pid);
console.log(serverProcess.killed);
// Will log as true, but the process continues to run,
// requiring Ctrl+C on the node program
}, 5000);
Edit: I have tried using different signals for kill, including setting killSignal
in the options, but that has not remedied the problem. According to the node docs:
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').