get.js 824 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. var os = require('os');
  3. var platformToMethod = {
  4. darwin: 'ps',
  5. sunos: 'ps',
  6. freebsd: 'ps',
  7. netbsd: 'ps',
  8. win: 'wmic',
  9. linux: 'ps',
  10. aix: 'ps',
  11. };
  12. var methodToRequireFn = {
  13. ps: () => require("./ps"),
  14. wmic: () => require("./wmic")
  15. };
  16. var platform = os.platform();
  17. if (platform.startsWith('win')) {
  18. platform = 'win';
  19. }
  20. var method = platformToMethod[platform];
  21. /**
  22. * Gets the list of all the pids of the system.
  23. * @param {Function} callback Called when the list is ready.
  24. */
  25. function get(callback) {
  26. if (method === undefined) {
  27. callback(
  28. new Error(
  29. os.platform() +
  30. ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'
  31. )
  32. );
  33. }
  34. var list = methodToRequireFn[method]();
  35. list(callback);
  36. }
  37. module.exports = get;