Skip to content

Commit

Permalink
Better support for Darwin/Mac (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan authored and indexzero committed Nov 26, 2018
1 parent 6960468 commit 2b6476c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,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
Empty file modified bin/ps-tree.js
100644 → 100755
Empty file.
15 changes: 9 additions & 6 deletions index.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,12 +102,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':
Expand All @@ -114,6 +117,6 @@ function normalizeHeader(str) {
return 'STAT';
break;
default:
throw new Error('Unknown process listing header: ' + str);
return str
}
}

0 comments on commit 2b6476c

Please sign in to comment.