Skip to content

Commit

Permalink
fix: windows 8 doesn't support windows-kill
Browse files Browse the repository at this point in the history
Fixes #1876
  • Loading branch information
remy committed Jul 8, 2021
1 parent 5bb92d4 commit 6c6cb65
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/monitor/run.js
Expand Up @@ -16,6 +16,7 @@ var restart = null;
var psTree = require('pstree.remy');
var path = require('path');
var signals = require('./signals');
const osRelease = require('os').release();

function run(options) {
var cmd = config.command.raw;
Expand Down Expand Up @@ -312,19 +313,26 @@ function kill(child, signal, callback) {
}

if (utils.isWindows) {
const taskKill = () => {
try {
exec('taskkill /pid ' + child.pid + ' /T /F');
} catch (e) {
utils.log.error("Could not shutdown sub process cleanly");
}
}

// We are handling a 'SIGKILL' POSIX signal under Windows the
// same way it is handled on a UNIX system: We are performing
// a hard shutdown without waiting for the process to clean-up.
if (signal === 'SIGKILL') {
if (signal === 'SIGKILL' || osRelease < 10) {

debug('terminating process group by force: %s', child.pid);

// We are using the taskkill utility to terminate the whole
// process group ('/t') of the child ('/pid') by force ('/f').
// We need to end all sub processes, because the 'child'
// process in this context is actually a cmd.exe wrapper.
exec(`taskkill /f /t /pid ${child.pid}`);
taskKill();
callback();
return;
}
Expand Down Expand Up @@ -357,9 +365,13 @@ function kill(child, signal, callback) {
// Therefore we are using 'start' to create a new cmd.exe context.
// The '/min' option hides the new terminal window and the '/wait'
// option lets the process wait for the command to finish.
execSync(
`start "windows-kill" /min /wait "${windowsKill}" -SIGINT ${processId}`
);
try {
execSync(
`start "windows-kill" /min /wait "${windowsKill}" -SIGINT ${processId}`
);
} catch (e) {
taskKill();
}
callback();

} else {
Expand Down

0 comments on commit 6c6cb65

Please sign in to comment.