Guest User

Untitled

a guest
Jan 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. var exec = require("child_process").exec,
  2. sys = require("sys");
  3.  
  4. var DEBUG = false;
  5.  
  6. function getProcessInfo (process, cb) {
  7. var cmd = DEBUG ? "ps -aux" : "ps",
  8. lists,
  9. i,
  10. line,
  11. headers,
  12. ret = {};
  13. console.log("commmand line " + cmd);
  14.  
  15.  
  16. cb = cb || function() {};
  17. try {
  18. exec(cmd, function(err, out) {
  19. if(err) {
  20. console.log("[CloudAPI] Failed to kill process");
  21. console.log(sys.inspect(err));
  22. cb(err, null);
  23. } else {
  24. if(out) {
  25. lists = out.split("\n");
  26. headers = lists.shift();
  27. i = lists.length;
  28. console.log(lists);
  29.  
  30. while(i--) {
  31. if(lists[i].indexOf(process) > -1) {
  32. line = lists[i];
  33. break;
  34. }
  35. }
  36. i = headers.length;
  37. console.log(headers);
  38.  
  39. while(i--) {
  40. ret[headers[i]] = line[i];
  41. }
  42. console.log(ret);
  43.  
  44. cb(null, ret);
  45. } else {
  46. cb(new Error("incorrect output"), null);
  47. }
  48. }
  49. });
  50. } catch(e) {
  51. console.log("[CloudAPI] Failed to execute command");
  52. cb(new Error("failed to execute command"), null);
  53. }
  54. }
  55.  
  56. getProcessInfo("com.aliyun.homeshell");
  57.  
  58. module.exports = exports = getProcessInfo;
Add Comment
Please, Sign In to add comment