Skip to content

Commit 0afe802

Browse files
authored
Merge pull request #193 from NativeScript/iiivanov/proc-kill-2
Fix process kill
2 parents 5431b85 + 4a553f0 commit 0afe802

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@types/mocha": "^5.2.1",
3838
"@types/node": "6.0.46",
3939
"@types/universal-analytics": "0.4.1",
40+
"cpx": "^1.5.0",
4041
"mocha": "^5.2.0",
4142
"sinon": "^5.0.10",
4243
"tslint": "5.10.0",
@@ -49,7 +50,7 @@
4950
"scripts": {
5051
"clean": "git clean -fdx",
5152
"postinstall": "node ./node_modules/vscode/bin/install",
52-
"build": "tsc -p ./src",
53+
"build": "tsc -p ./src && cpx src/common/*.sh out/common",
5354
"package": "vsce package",
5455
"full-build": "npm run clean && npm install && npm run build && npm run package",
5556
"launch-as-server": "node --nolazy ./out/debug-adapter/nativeScriptDebug.js --server=4712",

src/common/terminateProcess.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
terminateTree() {
4+
for cpid in $(/usr/bin/pgrep -P $1); do
5+
terminateTree $cpid
6+
done
7+
kill -9 $1 > /dev/null 2>&1
8+
}
9+
10+
for pid in $*; do
11+
terminateTree $pid
12+
done

src/common/utilities.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
import { ChildProcess, exec } from 'child_process';
1+
import { ChildProcess, execSync } from 'child_process';
22
import * as os from 'os';
3+
import * as path from 'path';
4+
import { ILogger, LogLevel } from '../common/logger';
35

4-
export function killProcess(childProcess: ChildProcess): void {
5-
switch (process.platform) {
6-
case 'win32':
7-
exec(`taskkill /pid ${childProcess.pid} /T /F`);
8-
break;
6+
export function killProcess(childProcess: ChildProcess, logger?: ILogger): void {
7+
logger && logger.log(`Stopping process: ${childProcess.pid}`);
98

10-
default:
11-
childProcess.kill('SIGINT');
12-
break;
9+
try {
10+
switch (process.platform) {
11+
case 'win32':
12+
execSync(`taskkill /pid ${childProcess.pid} /T /F`);
13+
break;
14+
15+
default:
16+
const cmd = path.join(__dirname, 'terminateProcess.sh');
17+
18+
execSync(`${cmd} ${childProcess.pid.toString()}`);
19+
break;
20+
}
21+
} catch (error) {
22+
logger && logger.log(error, LogLevel.Error);
1323
}
1424
}
1525

0 commit comments

Comments
 (0)