Linux ps コマンド

Linux コマンド大全

Linux ps (英語の正式名称: process status) コマンドは現在のプロセスの状態を表示するために使用され、Windows のタスクマネージャーに似ています。

構文

ps [options] [--help]

パラメータ:

  • ps のパラメータは非常に多いですが、ここではよく使われるいくつかのパラメータだけを挙げて、その意味を大まかに紹介します。
  • -A すべてのプロセスを一覧表示
  • -w 表示を拡幅して、より多くの情報を表示できる
  • -au より詳細な情報を表示
  • -aux 他のユーザーのプロセスも含むすべてのプロセスを表示
  • au(x) 出力形式 :

    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    • USER: プロセスの所有者
    • PID: pid
    • %CPU: 使用中の CPU 使用率
    • %MEM: 使用中のメモリ使用率
    • VSZ: 使用中の仮想メモリサイズ
    • RSS: 使用中のメモリサイズ
    • TTY: 端末の副装置番号 (minor device number of tty)
    • STAT: そのプロセスの状態:

      • D: 中断できない休止状態 (通常 IO のプロセス)
      • R: 実行中
      • S: スリープ状態
      • T: 実行を一時停止
      • Z: 存在しないが、一時的に消去できない
      • W: 割り当てるのに十分なメモリページがない
      • <: 高優先度のプロセス
      • N: 低優先度のプロセス
      • L: メモリページが割り当てられ、メモリ内にロックされている (リアルタイムシステムまたはI/O待ち)
    • START: プロセスの開始時間
    • TIME: 実行時間
    • COMMAND: 実行されたコマンド

実例

指定したプロセスを検索する形式:

ps -ef | grep 进程关键字

例: php のプロセスを表示:

# ps -ef | grep php
root       794     1  0  2020 ?        00:00:52 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
www-data   951   794  0  2020 ?        00:24:15 php-fpm: pool www
www-data   953   794  0  2020 ?        00:24:14 php-fpm: pool www
www-data   954   794  0  2020 ?        00:24:29 php-fpm: pool www
...

プロセス情報を表示:

# ps -A 
PID TTY     TIME CMD
  1 ?    00:00:02 init
  2 ?    00:00:00 kthreadd
  3 ?    00:00:00 migration/0
  4 ?    00:00:00 ksoftirqd/0
  5 ?    00:00:00 watchdog/0
  6 ?    00:00:00 events/0
  7 ?    00:00:00 cpuset
  8 ?    00:00:00 khelper
  9 ?    00:00:00 netns
  10 ?    00:00:00 async/mgr
  11 ?    00:00:00 pm
  12 ?    00:00:00 sync_supers
  13 ?    00:00:00 bdi-default
  14 ?    00:00:00 kintegrityd/0
  15 ?    00:00:02 kblockd/0
  16 ?    00:00:00 kacpid
  17 ?    00:00:00 kacpi_notify
  18 ?    00:00:00 kacpi_hotplug
  19 ?    00:00:27 ata/0
……省略部分结果
30749 pts/0  00:00:15 gedit
30886 ?    00:01:10 qtcreator.bin
30894 ?    00:00:00 qtcreator.bin 
31160 ?    00:00:00 dhclient
31211 ?    00:00:00 aptd
31302 ?    00:00:00 sshd
31374 pts/2  00:00:00 bash
31396 pts/2  00:00:00 ps

指定したユーザーの情報を表示

# ps -u root //显示root进程用户信息
 PID TTY     TIME CMD
  1 ?    00:00:02 init
  2 ?    00:00:00 kthreadd
  3 ?    00:00:00 migration/0
  4 ?    00:00:00 ksoftirqd/0
  5 ?    00:00:00 watchdog/0
  6 ?    00:00:00 events/0
  7 ?    00:00:00 cpuset
  8 ?    00:00:00 khelper
  9 ?    00:00:00 netns
  10 ?    00:00:00 async/mgr
  11 ?    00:00:00 pm
  12 ?    00:00:00 sync_supers
  13 ?    00:00:00 bdi-default
  14 ?    00:00:00 kintegrityd/0
  15 ?    00:00:02 kblockd/0
  16 ?    00:00:00 kacpid
……省略部分结果
30487 ?    00:00:06 gnome-terminal
30488 ?    00:00:00 gnome-pty-helpe
30489 pts/0  00:00:00 bash
30670 ?    00:00:00 debconf-communi 
30749 pts/0  00:00:15 gedit
30886 ?    00:01:10 qtcreator.bin
30894 ?    00:00:00 qtcreator.bin 
31160 ?    00:00:00 dhclient
31211 ?    00:00:00 aptd
31302 ?    00:00:00 sshd
31374 pts/2  00:00:00 bash
31397 pts/2  00:00:00 ps

コマンドラインも含めてすべてのプロセス情報を表示

# ps -ef //显示所有命令,连带命令行
UID    PID PPID C STIME TTY     TIME CMD
root     1   0 0 10:22 ?    00:00:02 /sbin/init
root     2   0 0 10:22 ?    00:00:00 [kthreadd]
root     3   2 0 10:22 ?    00:00:00 [migration/0]
root     4   2 0 10:22 ?    00:00:00 [ksoftirqd/0]
root     5   2 0 10:22 ?    00:00:00 [watchdog/0]
root     6   2 0 10:22 ?    /usr/lib/NetworkManager
……省略部分结果
root   31302 2095 0 17:42 ?    00:00:00 sshd: root@pts/2 
root   31374 31302 0 17:42 pts/2  00:00:00 -bash
root   31400   1 0 17:46 ?    00:00:00 /usr/bin/python /usr/sbin/aptd
root   31407 31374 0 17:48 pts/2  00:00:00 ps -ef

Linux コマンド大全

その他の拡張