(processId: number, logger: ILogger)
| 9 | * Kills the tree of processes starting at the given parent ID. |
| 10 | */ |
| 11 | export function killTree(processId: number, logger: ILogger): boolean { |
| 12 | if (process.platform === 'win32') { |
| 13 | const windir = process.env['WINDIR'] || 'C:\\Windows'; |
| 14 | const TASK_KILL = join(windir, 'System32', 'taskkill.exe'); |
| 15 | |
| 16 | // when killing a process in Windows its child processes are *not* killed but become root processes. |
| 17 | // Therefore we use TASKKILL.EXE |
| 18 | try { |
| 19 | execSync(`${TASK_KILL} /F /T /PID ${processId}`); |
| 20 | return true; |
| 21 | } catch (err) { |
| 22 | logger.error(LogTag.RuntimeException, 'Error running taskkill.exe', err); |
| 23 | return false; |
| 24 | } |
| 25 | } else { |
| 26 | // on linux and OS X we kill all direct and indirect child processes as well |
| 27 | try { |
| 28 | const cmd = join(__dirname, './terminateProcess.sh'); |
| 29 | const r = spawnSync('sh', [cmd, processId.toString()]); |
| 30 | if (r.stderr && r.status) { |
| 31 | logger.error(LogTag.RuntimeException, 'Error running terminateProcess', r); |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | return true; |
| 36 | } catch (err) { |
| 37 | logger.error(LogTag.RuntimeException, 'Error running terminateProcess', err); |
| 38 | return false; |
| 39 | } |
| 40 | } |
| 41 | } |
no test coverage detected