diff --git a/lib/forever.js b/lib/forever.js index de71f82d..73ba778d 100644 --- a/lib/forever.js +++ b/lib/forever.js @@ -853,13 +853,18 @@ forever.checkProcess = function (pid, callback) { return callback(false); } - exec('ps ' + pid + ' | grep -v PID', function (err, stdout, stderr) { - if (err) { - return callback(false); - } - - callback(stdout.indexOf(pid) !== -1); - }); + try { + // + // Trying to kill non-existent process here raises a ESRCH - no such + // process exception. Also, signal 0 doesn't do no harm to a process - it + // only checks if sending a singal to a given process is possible. + // + process.kill(pid, 0); + callback(true); + } + catch (err) { + callback(false); + } }; // @@ -910,4 +915,4 @@ forever.columns = { return timespan.fromDates(new Date(proc.ctime), new Date()).toString().yellow; } } -}; \ No newline at end of file +};