Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for Darwin/Mac #17

Merged
merged 14 commits into from
Nov 26, 2018
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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':
Expand All @@ -113,6 +116,6 @@ function normalizeHeader(str) {
return 'STAT';
break;
default:
throw new Error('Unknown process listing header: ' + str);
return str
}
}