get.js 721 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 platform = os.platform();
  13. if (platform.startsWith('win')) {
  14. platform = 'win';
  15. }
  16. var file = platformToMethod[platform];
  17. /**
  18. * Gets the list of all the pids of the system.
  19. * @param {Function} callback Called when the list is ready.
  20. */
  21. function get(callback) {
  22. if (file === undefined) {
  23. callback(
  24. new Error(
  25. os.platform() +
  26. ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'
  27. )
  28. );
  29. }
  30. var list = require('./' + file);
  31. list(callback);
  32. }
  33. module.exports = get;