third_party/tree-kill: always use the default pgrep on mac
The proctools' pgrep is problematic when running with -P.
Fixes golang/vscode-go#90
Change-Id: If3e306cd725a7c88873ca40d74c1581e2d695ea4
Change-Id: If3e306cd725a7c88873ca40d74c1581e2d695ea4
GitHub-Last-Rev: 2933f719f16735de1e841d31113d1f8759a7b050
GitHub-Pull-Request: golang/vscode-go#174
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/236538
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/third_party/tree-kill/index.js b/third_party/tree-kill/index.js
index 8df6a0f..9499a89 100755
--- a/third_party/tree-kill/index.js
+++ b/third_party/tree-kill/index.js
@@ -1,6 +1,7 @@
'use strict';
var childProcess = require('child_process');
+const { existsSync } = require('fs');
var spawn = childProcess.spawn;
var exec = childProcess.exec;
@@ -30,7 +31,7 @@
break;
case 'darwin':
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
- return spawn('pgrep', ['-P', parentPid]);
+ return spawn(pathToPgrep(), ['-P', parentPid]);
}, function () {
killAll(tree, signal, callback);
});
@@ -116,3 +117,20 @@
ps.on('close', onClose);
}
+
+var pgrep = '';
+function pathToPgrep () {
+ if (pgrep) {
+ return pgrep;
+ }
+ // Use the default pgrep, available since os x mountain lion.
+ // proctools' pgrep does not implement `-P` correctly and returns
+ // unrelated processes.
+ // https://github.com/golang/vscode-go/issues/90#issuecomment-634430428
+ try {
+ pgrep = existsSync('/usr/bin/pgrep') ? '/usr/bin/pgrep' : 'pgrep';
+ } catch (e) {
+ pgrep = 'pgrep';
+ }
+ return pgrep;
+}
\ No newline at end of file