38
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mac でも ps コマンドでプロセスのツリーを表示したい(--forest)

Last updated at Posted at 2016-09-06

mac の ps コマンドには、-f (--forest) 無い。

% ps auxf
ps: illegal option -- f
usage: ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid...]]
          [-u]
          [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
       ps [-L]

代わりと言っちゃなんですが、pstree というのがあるらしい。

% brew install pstree

こんな感じで微妙に表示が違うけど、満足。

-+= 00001 root /sbin/launchd
 |--= 00045 root /usr/sbin/syslogd
 |--= 00046 root /usr/libexec/UserEventAgent (System)
 |--= 00048 root /usr/libexec/kextd
 |--= 00049 root /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/Support/fseventsd
(以下略)

で、以下余談。
pstree の表示結果に pstree 自体を発見。

 |         \--- 40396 root ps -axwwo user,pid,ppid,pgid,command

内部的には、上記オプションで ps コマンドを実行してるみたい。
てことで、同じコマンドを試した結果が下記。

% ps -axwwo user,pid,ppid,pgid,command
USER              PID  PPID  PGID COMMAND
root                1     0     1 /sbin/launchd
root               45     1    45 /usr/sbin/syslogd
root               46     1    46 /usr/libexec/UserEventAgent (System)
root               48     1    48 /usr/libexec/kextd
root               49     1    49 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/Support/fseventsd
(以下略)

これらの情報を、うまいこと加工して表示してくれてるのね。

38
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?