diff --git a/README.md b/README.md index a3f9e8d..66297ef 100644 --- a/README.md +++ b/README.md @@ -80,4 +80,15 @@ System 0 4 smss.exe 4 228 ``` +### Mac/Darwin + +1. " " need to be striped + +```shell +$ ps -A -o comm,ppid,pid,stat +COMM PPID PID STAT +/sbin/launchd 0 1 Ss +/usr/libexec/Use 1 43 Ss +``` + ### LICENSE: MIT diff --git a/bin/ps-tree.js b/bin/ps-tree.js old mode 100644 new mode 100755 diff --git a/index.js b/index.js old mode 100755 new mode 100644 index 24e3284..6fe23cd --- a/index.js +++ b/index.js @@ -28,6 +28,12 @@ module.exports = function childrenOfPid(pid, callback) { // ps 20688 16965 R+ // ``` // + // Darwin: + // $ ps -A -o comm,ppid,pid,stat + // COMM PPID PID STAT + // /sbin/launchd 0 1 Ss + // /usr/libexec/Use 1 43 Ss + // // Win32: // 1. wmic PROCESS WHERE ParentProcessId=4604 GET Name,ParentProcessId,ProcessId,Status) // 2. The order of head columns is fixed @@ -95,12 +101,9 @@ module.exports = function childrenOfPid(pid, callback) { * @param {string} str Header string to normalize */ function normalizeHeader(str) { - if (process.platform !== 'win32') { - return str; - } - switch (str) { - case 'Name': + case 'Name': // for win32 + case 'COMM': // for darwin return 'COMMAND'; break; case 'ParentProcessId': @@ -113,6 +116,6 @@ function normalizeHeader(str) { return 'STAT'; break; default: - throw new Error('Unknown process listing header: ' + str); + return str } }