Skip to content

Commit

Permalink
馃悰 use pidtree
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Nov 24, 2018
1 parent 7ec542e commit 1b41ac5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
35 changes: 18 additions & 17 deletions lib/spawn-posix.js
Expand Up @@ -11,6 +11,7 @@
//------------------------------------------------------------------------------

const crossSpawn = require("cross-spawn")
const getDescendentProcessInfo = require("pidtree")

//------------------------------------------------------------------------------
// Helpers
Expand All @@ -21,22 +22,22 @@ const crossSpawn = require("cross-spawn")
* @this ChildProcess
* @returns {void}
*/
// function kill() {
// getDescendentProcessInfo(this.pid, (err, descendent) => {
// if (err) {
// return
// }

// for (const child of descendent) {
// try {
// process.kill(child.PID)
// }
// catch (_err) {
// // ignore.
// }
// }
// })
// }
function kill() {
getDescendentProcessInfo(this.pid, { root: true }, (err, pids) => {
if (err) {
return
}

for (const pid of pids) {
try {
process.kill(pid)
}
catch (_err) {
// ignore.
}
}
})
}

//------------------------------------------------------------------------------
// Public Interface
Expand All @@ -57,7 +58,7 @@ const crossSpawn = require("cross-spawn")
*/
module.exports = function spawn(command, args, options) {
const child = crossSpawn(command, args, options)
// child.kill = kill
child.kill = kill

return child
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"cross-spawn": "^6.0.5",
"memorystream": "^0.3.1",
"minimatch": "^3.0.4",
"pidtree": "^0.3.0",
"read-pkg": "^3.0.0",
"shell-quote": "^1.6.1",
"string.prototype.padend": "^3.0.0"
Expand Down

0 comments on commit 1b41ac5

Please sign in to comment.