Skip to content

Commit

Permalink
third_party/tree-kill: always use the default pgrep on mac
Browse files Browse the repository at this point in the history
The proctools' pgrep is problematic when running with -P.

Fixes #90

Change-Id: If3e306cd725a7c88873ca40d74c1581e2d695ea4

Change-Id: If3e306cd725a7c88873ca40d74c1581e2d695ea4
GitHub-Last-Rev: 2933f71
GitHub-Pull-Request: #174
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/236538
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
  • Loading branch information
hyangah committed Jun 17, 2020
1 parent cdde556 commit bf28864
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion 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;

Expand Down Expand Up @@ -30,7 +31,7 @@ module.exports = function (pid, signal, callback) {
break;
case 'darwin':
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
return spawn('pgrep', ['-P', parentPid]);
return spawn(pathToPgrep(), ['-P', parentPid]);
}, function () {
killAll(tree, signal, callback);
});
Expand Down Expand Up @@ -116,3 +117,20 @@ function buildProcessTree (parentPid, tree, pidsToProcess, spawnChildProcessesLi

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;
}

0 comments on commit bf28864

Please sign in to comment.