aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/utils')
-rw-r--r--editors/code/src/utils/processes.ts40
-rw-r--r--editors/code/src/utils/terminateProcess.sh12
2 files changed, 52 insertions, 0 deletions
diff --git a/editors/code/src/utils/processes.ts b/editors/code/src/utils/processes.ts
new file mode 100644
index 000000000..09fdf6e24
--- /dev/null
+++ b/editors/code/src/utils/processes.ts
@@ -0,0 +1,40 @@
1'use strict';
2
3import * as cp from 'child_process';
4import ChildProcess = cp.ChildProcess;
5
6import { join } from 'path';
7
8const isWindows = (process.platform === 'win32');
9const isMacintosh = (process.platform === 'darwin');
10const isLinux = (process.platform === 'linux');
11export function terminate(process: ChildProcess, cwd?: string): boolean {
12 if (isWindows) {
13 try {
14 // This we run in Atom execFileSync is available.
15 // Ignore stderr since this is otherwise piped to parent.stderr
16 // which might be already closed.
17 const options: any = {
18 stdio: ['pipe', 'pipe', 'ignore']
19 };
20 if (cwd) {
21 options.cwd = cwd
22 }
23 (cp).execFileSync('taskkill', ['/T', '/F', '/PID', process.pid.toString()], options);
24 return true;
25 } catch (err) {
26 return false;
27 }
28 } else if (isLinux || isMacintosh) {
29 try {
30 const cmd = join(__dirname, 'terminateProcess.sh');
31 const result = cp.spawnSync(cmd, [process.pid.toString()]);
32 return result.error ? false : true;
33 } catch (err) {
34 return false;
35 }
36 } else {
37 process.kill('SIGKILL');
38 return true;
39 }
40} \ No newline at end of file
diff --git a/editors/code/src/utils/terminateProcess.sh b/editors/code/src/utils/terminateProcess.sh
new file mode 100644
index 000000000..2ec9e1c2e
--- /dev/null
+++ b/editors/code/src/utils/terminateProcess.sh
@@ -0,0 +1,12 @@
1#!/bin/bash
2
3terminateTree() {
4 for cpid in $(pgrep -P $1); do
5 terminateTree $cpid
6 done
7 kill -9 $1 > /dev/null 2>&1
8}
9
10for pid in $*; do
11 terminateTree $pid
12done \ No newline at end of file