var enforceProcesses = function(processes) { ps.list({}, function(err, result) { for(var i=0; i<result.length; i++) { if (!processes[result[i].command] && !allowable(result[i]) ) { killer = child_process.spawn("sudo", ["kill", "-9", result[i].pid]); console.log("Killed " + result[i].command + " using PID:" + killer.pid); } } }); }
function findByCommand(command, callback) { ps.list({name: command}, function(err, result) { if(err) { return callback(err); } if(result.length === 0) { return callback(new Error("Cannot find a process for '" + command + "'.")); } if(result.length > 1) { return callback(new Error("More than one command found for '" + command + "'.")); } callback(null, findByPid(result[0].pid)); }); }