Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var exec = require("child_process").exec,
- sys = require("sys");
- var DEBUG = false;
- function getProcessInfo (process, cb) {
- var cmd = DEBUG ? "ps -aux" : "ps",
- lists,
- i,
- line,
- headers,
- ret = {};
- console.log("commmand line " + cmd);
- cb = cb || function() {};
- try {
- exec(cmd, function(err, out) {
- if(err) {
- console.log("[CloudAPI] Failed to kill process");
- console.log(sys.inspect(err));
- cb(err, null);
- } else {
- if(out) {
- lists = out.split("\n");
- headers = lists.shift();
- i = lists.length;
- console.log(lists);
- while(i--) {
- if(lists[i].indexOf(process) > -1) {
- line = lists[i];
- break;
- }
- }
- i = headers.length;
- console.log(headers);
- while(i--) {
- ret[headers[i]] = line[i];
- }
- console.log(ret);
- cb(null, ret);
- } else {
- cb(new Error("incorrect output"), null);
- }
- }
- });
- } catch(e) {
- console.log("[CloudAPI] Failed to execute command");
- cb(new Error("failed to execute command"), null);
- }
- }
- getProcessInfo("com.aliyun.homeshell");
- module.exports = exports = getProcessInfo;
Add Comment
Please, Sign In to add comment