Skip to content

Commit 1b41ac5

Browse files
committed
🐛 use pidtree
1 parent 7ec542e commit 1b41ac5

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lib/spawn-posix.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//------------------------------------------------------------------------------
1212

1313
const crossSpawn = require("cross-spawn")
14+
const getDescendentProcessInfo = require("pidtree")
1415

1516
//------------------------------------------------------------------------------
1617
// Helpers
@@ -21,22 +22,22 @@ const crossSpawn = require("cross-spawn")
2122
* @this ChildProcess
2223
* @returns {void}
2324
*/
24-
// function kill() {
25-
// getDescendentProcessInfo(this.pid, (err, descendent) => {
26-
// if (err) {
27-
// return
28-
// }
29-
30-
// for (const child of descendent) {
31-
// try {
32-
// process.kill(child.PID)
33-
// }
34-
// catch (_err) {
35-
// // ignore.
36-
// }
37-
// }
38-
// })
39-
// }
25+
function kill() {
26+
getDescendentProcessInfo(this.pid, { root: true }, (err, pids) => {
27+
if (err) {
28+
return
29+
}
30+
31+
for (const pid of pids) {
32+
try {
33+
process.kill(pid)
34+
}
35+
catch (_err) {
36+
// ignore.
37+
}
38+
}
39+
})
40+
}
4041

4142
//------------------------------------------------------------------------------
4243
// Public Interface
@@ -57,7 +58,7 @@ const crossSpawn = require("cross-spawn")
5758
*/
5859
module.exports = function spawn(command, args, options) {
5960
const child = crossSpawn(command, args, options)
60-
// child.kill = kill
61+
child.kill = kill
6162

6263
return child
6364
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"cross-spawn": "^6.0.5",
3535
"memorystream": "^0.3.1",
3636
"minimatch": "^3.0.4",
37+
"pidtree": "^0.3.0",
3738
"read-pkg": "^3.0.0",
3839
"shell-quote": "^1.6.1",
3940
"string.prototype.padend": "^3.0.0"

0 commit comments

Comments
 (0)