Hack 91. Ps コマンド

ps コマンド (process status) はアクティブなプロセスすべてのスナップショット情報を表示します。

Syntax: ps [options]

システムで実行中のプロセスすべてを表示するには?

以下に示すように "ps aux" を使用します。

# ps aux | more
USER     PID %CPU %MEM   VSZ   RSS TTY STAT START TIME COMMAND
root       1  0.0  0.0  2044   588 ?   Ss   Jun27 0:00 init [5]
apache 31186  0.0  1.6 23736 17556 ?   S    Jul26 0:40 /usr/local/apache2/bin/httpd
apache 31187  0.0  1.3 20640 14444 ?   S    Jul26 0:37 /usr/local/apache2/bin/httpd

"ps -ef | more" を使用することもできます。同じ出力になります。


プロセスツリーを出力する

ツリー形式でプロセスを表示するには、"ps axuf" または "ps –ejH" どちらでも使用できます。
ツリー構造はプロセスを図式化するのに役立ち、すぐに親プロセスを判断できます。
ある目的のために、カラムの中には以下のように出力でカットされます。

# ps axuf
root Oct14 0:00 /opt/VRTSralus/bin/beremote
root Oct14 0:00  \_ /opt/VRTSralus/bin/beremote
root Oct14 0:00   \_ /opt/VRTSralus/bin/beremote
root Oct14 0:00   \_ /opt/VRTSralus/bin/beremote
root Oct14 0:01   \_ /opt/VRTSralus/bin/beremote
root Oct 14 0:00  \_ /opt/VRTSralus/bin/beremote
root Dec03 0:01 /usr/local/sbin/sshd
root Dec22 1:08 /usr/local/sbin/sshd
root 23:35 0:00  \_ /usr/local/sbin/sshd
511 23:35 0:00    \_ -bash
511                \_ ps axuf

Note: ツリー構造でプロセスを表示するには pstree コマンドも使用できます。


指定したユーザが所有するプロセスを表示する

次のコマンドは、Linux ユーザ名: oracle が所有するプロセスすべてを表示します。

$ ps U oracle
PID  TTY STAT TIME COMMAND
5014 ?   Ss   0:01 /oracle/bin/tnslsnr
7124 ?   Ss   0:00 ora_q002_med
8206 ?   Ss   0:00 ora_cjq0_med
8852 ?   Ss   0:01 ora_pmon_med
8854 ?   Ss   0:00 ora_psp0_med
8911 ?   Ss   0:02 oraclemed (LOCAL=NO)

カレントユーザが所有するプロセスを表示する

次のコマンドはカレントユーザが所有するプロセスすべてを表示します。

$ ps U $USER
PID   TTY    STAT TIME  COMMAND
10329 ?      S    0:00  sshd: ramesh@pts/1,pts/2
10330 pts/1  Ss   0:00  -bash
10354 pts/2  Ss+  0:00  -bash
10530 pts/1  R+   0:00  ps U ramesh