Skip to content

Commit

Permalink
[fix] Use process.kill to check if process is alive
Browse files Browse the repository at this point in the history
Old solution spawned `ps <pid> | grep -v PID` to perform this check.
  • Loading branch information
mmalecki authored and indexzero committed Oct 22, 2011
1 parent d791422 commit f820056
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

//
Expand Down Expand Up @@ -910,4 +915,4 @@ forever.columns = {
return timespan.fromDates(new Date(proc.ctime), new Date()).toString().yellow;
}
}
};
};

0 comments on commit f820056

Please sign in to comment.