This repository has been archived by the owner on Nov 12, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: unnecessary terminate logic"
This reverts commit 141341a.
- Loading branch information
Guillaume Chau
committed
Oct 22, 2019
1 parent
f0b8207
commit b3ca562
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// OS | ||
exports.isWindows = process.platform === 'win32' | ||
exports.isMacintosh = process.platform === 'darwin' | ||
exports.isLinux = process.platform === 'linux' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const util = require('util') | ||
const cp = require('child_process') | ||
const path = require('path') | ||
const { | ||
isWindows, | ||
isLinux, | ||
isMacintosh, | ||
} = require('./platform') | ||
|
||
const execFile = util.promisify(cp.execFile) | ||
const spawn = util.promisify(cp.spawn) | ||
|
||
exports.terminate = async function (childProcess, cwd) { | ||
if (isWindows) { | ||
try { | ||
let options = { | ||
stdio: ['pipe', 'pipe', 'ignore'], | ||
} | ||
if (cwd) { | ||
options.cwd = cwd | ||
} | ||
await execFile('taskkill', ['/T', '/F', '/PID', childProcess.pid.toString()], options) | ||
} catch (err) { | ||
return { success: false, error: err } | ||
} | ||
} else if (isLinux || isMacintosh) { | ||
try { | ||
let cmd = path.resolve(__dirname, './terminate.sh') | ||
let result = await spawn(cmd, [childProcess.pid.toString()], { | ||
cwd, | ||
}) | ||
if (result.error) { | ||
return { success: false, error: result.error } | ||
} | ||
} catch (err) { | ||
return { success: false, error: err } | ||
} | ||
} else { | ||
childProcess.kill('SIGKILL') | ||
} | ||
return { success: true } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
terminateTree() { | ||
for cpid in $(/usr/bin/pgrep -P $1); do | ||
terminateTree $cpid | ||
done | ||
kill -9 $1 > /dev/null 2>&1 | ||
} | ||
|
||
for pid in $*; do | ||
terminateTree $pid | ||
done |