summaryrefslogtreecommitdiffstats
path: root/node_modules/pidtree/lib/get.js
blob: 1793d54cbd1bee09b62b833bad31d2848e31623a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';

var os = require('os');

var platformToMethod = {
  darwin: 'ps',
  sunos: 'ps',
  freebsd: 'ps',
  netbsd: 'ps',
  win: 'wmic',
  linux: 'ps',
  aix: 'ps'
};

var platform = os.platform();
if (platform.startsWith('win')) {
  platform = 'win';
}

var file = platformToMethod[platform];

/**
 * Gets the list of all the pids of the system.
 * @param  {Function} callback Called when the list is ready.
 */
function get(callback) {
  if (file === undefined) {
    callback(
      new Error(
        os.platform() +
          ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'
      )
    );
  }

  var list = require('./' + file);
  list(callback);
}

module.exports = get;