Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer /usr/bin/pgrep to other pgrep if available #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}