Skip to content

Commit 2b6476c

Browse files
huanindexzero
authored andcommitted
Better support for Darwin/Mac (#17)
1 parent 6960468 commit 2b6476c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,15 @@ System 0 4
7878
smss.exe 4 228
7979
```
8080

81+
### Mac/Darwin
82+
83+
1. " " need to be striped
84+
85+
```shell
86+
$ ps -A -o comm,ppid,pid,stat
87+
COMM PPID PID STAT
88+
/sbin/launchd 0 1 Ss
89+
/usr/libexec/Use 1 43 Ss
90+
```
91+
8192
### LICENSE: MIT

bin/ps-tree.js

100644100755
File mode changed.

index.js

100755100644
+9-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ module.exports = function childrenOfPid(pid, callback) {
2828
// ps 20688 16965 R+
2929
// ```
3030
//
31+
// Darwin:
32+
// $ ps -A -o comm,ppid,pid,stat
33+
// COMM PPID PID STAT
34+
// /sbin/launchd 0 1 Ss
35+
// /usr/libexec/Use 1 43 Ss
36+
//
3137
// Win32:
3238
// 1. wmic PROCESS WHERE ParentProcessId=4604 GET Name,ParentProcessId,ProcessId,Status)
3339
// 2. The order of head columns is fixed
@@ -96,12 +102,9 @@ module.exports = function childrenOfPid(pid, callback) {
96102
* @param {string} str Header string to normalize
97103
*/
98104
function normalizeHeader(str) {
99-
if (process.platform !== 'win32') {
100-
return str;
101-
}
102-
103105
switch (str) {
104-
case 'Name':
106+
case 'Name': // for win32
107+
case 'COMM': // for darwin
105108
return 'COMMAND';
106109
break;
107110
case 'ParentProcessId':
@@ -114,6 +117,6 @@ function normalizeHeader(str) {
114117
return 'STAT';
115118
break;
116119
default:
117-
throw new Error('Unknown process listing header: ' + str);
120+
return str
118121
}
119122
}

0 commit comments

Comments
 (0)