From f7c6e0deebc614c309817dd790d117b0c9326ea2 Mon Sep 17 00:00:00 2001 From: Finn Kumkar Date: Sun, 9 May 2021 20:49:05 +0200 Subject: [PATCH] fix: add support for hard shutdown on SIGKILL (#1720) This commit adds back the hard shutdown behaviour under Windows as an opt-in: If the --signal option is "SIGKILL" nodemon will terminate the process group by force without waiting for the process to clean-up. This matches a SIGKILL on a UNIX system. --- lib/monitor/run.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/monitor/run.js b/lib/monitor/run.js index d78dd79e..c5f19b01 100644 --- a/lib/monitor/run.js +++ b/lib/monitor/run.js @@ -313,6 +313,22 @@ function kill(child, signal, callback) { if (utils.isWindows) { + // 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') { + + 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}`); + callback(); + return; + } + // We are using the Windows Management Instrumentation Command-line // (wmic.exe) to resolve the sub-child process identifier, because the // 'child' process in this context is actually a cmd.exe wrapper.