Skip to content

Commit

Permalink
prefer /usr/bin/pgrep to other pgrep if available
Browse files Browse the repository at this point in the history
Use the default pgrep, available since os x mountain lion.
proctools' pgrep does not implement `-P` correctly, returns
unrelated processes, breaks tree-kill's assumption, and may
cause a large number of pgrep processes.

Reported in pkrumins#17 (comment)

Update golang/vscode-go#90 (comment)
  • Loading branch information
hyangah committed Jun 17, 2020
1 parent cb47838 commit 05397b4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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 05397b4

Please sign in to comment.