ps コマンドメモ


オプション大杉＋BSDとGnuバージョンをサポートしてるため、フルカオスなので個人的によく使うオプションのみメモ


## BSD スタイルのオプション

全てのプロセスを、冗長的に表示

```shell
> ps awwux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  19200  1492 ?        Ss   May19   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    May19   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    May19   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    May19   2:14 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    May19   0:00 [migration/0]
root         6  0.0  0.0      0     0 ?        S    May19   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    May19   0:00 [migration/1]
root         8  0.0  0.0      0     0 ?        S    May19   0:00 [migration/1]
root         9  0.0  0.0      0     0 ?        S    May19   0:54 [ksoftirqd/1]
root        10  0.0  0.0      0     0 ?        S    May19   0:00 [watchdog/1]
root        11  0.0  0.0      0     0 ?        S    May19   0:00 [migration/2]
...
```


ps tree 形式で全てを表示

```shell
> ps axjf
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
    0     2     0     0 ?           -1 S        0   0:00 [kthreadd]
    2     3     0     0 ?           -1 S        0   0:00  \_ [migration/0]
    2     4     0     0 ?           -1 S        0   2:14  \_ [ksoftirqd/0]
    2     5     0     0 ?           -1 S        0   0:00  \_ [migration/0]
    2     6     0     0 ?           -1 S        0   0:00  \_ [watchdog/0]
    2     7     0     0 ?           -1 S        0   0:00  \_ [migration/1]
…
    1  1198  1198  1198 ?           -1 Ss       0   0:00 /usr/sbin/sshd
 1198 13062  1198  1198 ?           -1 S        0   0:00  \_ sshd: yasui [priv]
13062 13066  1198  1198 ?           -1 S      500   0:00      \_ sshd: yasui@pts/0
13066 13067 13067 13067 pts/0    13161 Ss     500   0:00          \_ -zsh
13067 13161 13161 13067 pts/0    13161 R+     500   0:00              \_ ps axjf
...
```


スレッド情報も表示する

```shell
> ps axms
  UID   PID          PENDING          BLOCKED          IGNORED           CAUGHT STAT TTY        TIME COMMAND
    0     1 0000000000000000                -                -                - -    ?          0:00 /sbin/init
    0     - 0000000000000000 0000000000000000 0000000000001000 00000001a0016623 Ss   -          0:00 -
    0     2 0000000000000000                -                -                - -    ?          0:00 [kthreadd]
    0     - 0000000000000000 0000000000000000 ffffffffffffffff 0000000000000000 S    -          0:00 -
    0     3 0000000000000000                -                -                - -    ?          0:00 [migration/0]
    0     - 0000000000000000 0000000000000000 ffffffffffffffff 0000000000000000 S    -          0:00 -
    0     4 0000000000000000                -                -                - -    ?          2:14 [ksoftirqd/0]
    0     - 0000000000000000 0000000000000000 ffffffffffffffff 0000000000000000 S    -          2:14 -
    0     5 0000000000000000                -                -                - -    ?          0:00 [migration/0]
    0     - 0000000000000000 0000000000000000 ffffffffffffffff 0000000000000000 S    -          0:00 -
    0     6 0000000000000000                -                -                - -    ?          0:00 [watchdog/0]
    0     - 0000000000000000 0000000000000000 ffffffffffffffff 0000000000000000 S    -          0:00 -
    0     7 0000000000000000                -        
...
```


セキュリティ情報も表示

```shell
> ps axZ 
LABEL                             PID TTY      STAT   TIME COMMAND
system_u:system_r:init_t:s0         1 ?        Ss     0:00 /sbin/init
system_u:system_r:kernel_t:s0       2 ?        S      0:00 [kthreadd]
system_u:system_r:kernel_t:s0       3 ?        S      0:00 [migration/0]
...
unconfined_u:system_r:httpd_t:s0 1989 ?        Ss     0:16 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 3563 ?        S      0:00 /usr/sbin/httpd
...
```