| 13 | const isMacintosh = (process.platform === 'darwin'); |
| 14 | const isLinux = (process.platform === 'linux'); |
| 15 | export function terminate(process: ChildProcess, cwd?: string): boolean { |
| 16 | if (isWindows) { |
| 17 | try { |
| 18 | // This we run in Atom execFileSync is available. |
| 19 | // Ignore stderr since this is otherwise piped to parent.stderr |
| 20 | // which might be already closed. |
| 21 | let options: any = { |
| 22 | stdio: ['pipe', 'pipe', 'ignore'] |
| 23 | }; |
| 24 | if (cwd) { |
| 25 | options.cwd = cwd |
| 26 | } |
| 27 | (<any>cp).execFileSync('taskkill', ['/T', '/F', '/PID', process.pid.toString()], options); |
| 28 | return true; |
| 29 | } catch (err) { |
| 30 | return false; |
| 31 | } |
| 32 | } else if (isLinux || isMacintosh) { |
| 33 | try { |
| 34 | var cmd = join(__dirname, 'terminateProcess.sh'); |
| 35 | var result = (<any>cp).spawnSync(cmd, [process.pid.toString()]); |
| 36 | return result.error ? false : true; |
| 37 | } catch (err) { |
| 38 | return false; |
| 39 | } |
| 40 | } else { |
| 41 | process.kill('SIGKILL'); |
| 42 | return true; |
| 43 | } |
| 44 | } |