ps命令初步使用

ps命令

全名:Process Status

功能:顯示某一時刻進程的狀態,report a snapshot of the current processes

使用權限:所有使用者

 

使用方式:ps [options] [--help]

  • UNIX 風格,選項可以組合在一起,並且選項前必須有“-”連字符

  • BSD 風格,選項可以組合在一起,但是選項前不能有“-”連字符

  • GNU 風格的長選項,選項前有兩個“-”連字符

 

常用參數:

  • a:所有與終端(指的是所有的終端,包括自己登錄的這個終端)相關的進程;

  • x:所有與終端無關的進程;

  • u:顯示進程所有者的用戶名

  • o:指定字段來顯示

  • -e:顯示所有進程(UNIX格式)

  • -f:顯示完整格式的進程信息

  • -H:以層級結構顯示進程的相關信息;

  • -F:顯示完整格式的進程信息;

  • –u:顯示指定用戶的進程

  • –l:僅顯示自己登錄的這個終端中的進程

  • –C:通過進程名顯示進程

 

實例:顯示與終端相關的進程

[root@Linux_11~]# ps a

  PID TTY     STAT   TIME COMMAND

 2477 tty1    Ss+    0:00 /sbin/mingetty/dev/tty1

 2479 tty2    Ss+    0:00 /sbin/mingetty/dev/tty2

 2481 tty3    Ss+    0:00 /sbin/mingetty/dev/tty3

 2483 tty4    Ss+    0:00 /sbin/mingetty/dev/tty4

 2486 tty5    Ss+    0:00 /sbin/mingetty/dev/tty5

 2488 tty6    Ss+    0:00 /sbin/mingetty/dev/tty6

 4558 pts/0   Ss     0:00 -bash

 4800 pts/0   S      0:00 su - wuxinbing

 4801 pts/0   S      0:00 –bash

 

 

實例:顯示與終端無關的進程

[root@Linux_11~]# ps x

  PID TTY     STAT   TIME COMMAND

    1 ?       Ss     0:01 /sbin/init

    2 ?       S      0:00 [kthreadd]

    3 ?       S      0:00 [migration/0]

    4 ?       S      0:00 [ksoftirqd/0]

    5 ?       S      0:00 [migration/0]

    6 ?       S      0:00 [watchdog/0]

    7 ?       S      0:00 [migration/1]

    8 ?       S      0:00 [migration/1]

    9 ?       S      0:00 [ksoftirqd/1]

   10 ?       S      0:00 [watchdog/1]

   11 ?       S      0:00 [migration/2]

   12 ?       S      0:00 [migration/2]

 

 

實例:以完整格式顯示所有的進程

[root@Linux_11~]# ps -ef

UID        PID PPID  C STIME TTY          TIME CMD

root         1    0  0 08:31 ?        00:00:01 /sbin/init

root         2    0  0 08:31 ?        00:00:00 [kthreadd]

root         3    2  0 08:31 ?        00:00:00 [migration/0]

root         4    2  0 08:31 ?        00:00:00 [ksoftirqd/0]

root         5    2  0 08:31 ?        00:00:00 [migration/0]

root         6    2  0 08:31 ?        00:00:00 [watchdog/0]

root         7    2  0 08:31 ?        00:00:00 [migration/1]

root         8    2  0 08:31 ?        00:00:00 [migration/1]

root         9    2  0 08:31 ?        00:00:00 [ksoftirqd/1]

 

 

實例:查看當前系統進程的uid,pid,stat,pri, uid號排序.

[root@Linux_11 dstat]# ps -eo pid,stat,pri,uid --sort uid

  PID STAT PRI  UID

    1 Ss   19     0

    2 S    19     0

    3 S   139     0

    4 S    19     0

    5 S   139     0

    6 S   139     0

    7 S   139     0

    8 S   139     0

    9 S    19     0

 

 

實例:顯示指定用戶相關的進程

[root@Linux_11 ~]# ps -u admin

  PID TTY          TIME CMD

 5042 pts/1   00:00:00 bash

 

 

實例:將目前屬於自己這次登入的 PID 與相關信息列示出來
[root@Linux_11 ~]# ps -l

F S   UID  PID  PPID  C PRI NI ADDR SZ WCHAN  TTY          TIME CMD

4 S     0 4558  4554  0 80   0 -  1739 -     pts/0    00:00:00 bash

4 S     0 4800  4558  0 80   0 -  2274 -     pts/0    00:00:00 su

4 S     0 4956  4801  0 80   0 -  2277 -     pts/0    00:00:00 su

4 S     0 4962  4956  0 80   0 -  1719 -     pts/0    00:00:00 bash

4 R     0 7244  4962  0 80   0 -  1624 -     pts/0    00:00:00 ps

 

實例:通過進程名顯示進程

[root@Linux_11 ~]# ps -Cnginx

  PID TTY          TIME CMD

 7288 ?       00:00:00 nginx

 7289 ?       00:00:00 nginx

提示:上面若要查看詳解的信息還可以使用-f參數

 

實例:以詳解格式顯示所有進程

[root@Linux_11 ~]# ps aux

USER       PID %CPU %MEM    VSZ  RSS TTY      STAT START   TIME COMMAND

root         1 0.0  0.2   2900 1436 ?        Ss   Dec25  0:01 /sbin/init

root         2 0.0  0.0      0    0 ?        S    Dec25  0:00 [kthreadd]

root         3 0.0  0.0      0    0 ?        S    Dec25  0:00 [migration/0]

root         4 0.0  0.0      0    0 ?        S    Dec25  0:00 [ksoftirqd/0]

root         5 0.0  0.0      0    0 ?        S    Dec25  0:00 [migration/0]

root         6 0.0  0.0      0    0 ?        S    Dec25  0:01 [watchdog/0]

root         7 0.0  0.0      0    0 ?        S    Dec25  0:00 [migration/1]

相關說明如下:

USER:啓動此進程的用戶名

VSZ:佔用的虛擬內存集;virtualmemory size

RSS:常駐內存集;Resident Size

STAT:進程的狀態

R:正在運行中;running

S:可中斷睡眠interruptable sleeping

D:不可中睡睡眠uninterruptable sleeping

T:停止Stopped

Z:殭屍zombie

+:前臺進程

l:多線程進程

N:低優先級進程

<:高優先級進程

 

 

 

實例:顯示詳解的進程

  • -e:顯示所有進程(UNIX格式)

  • -f:顯示完整格式的進程信息

 

[root@Linux_11 ~]# ps -ef

UID        PID PPID  C STIME TTY          TIME CMD

root         1    0  0 Dec25 ?        00:00:01 /sbin/init

root         2    0  0 Dec25 ?        00:00:00 [kthreadd]

root         3    2  0 Dec25 ?        00:00:00 [migration/0]

root         4    2  0 Dec25 ?        00:00:00 [ksoftirqd/0]

root         5    2  0 Dec25 ?        00:00:00 [migration/0]

root         6    2  0 Dec25 ?        00:00:01 [watchdog/0]

相關說明如下:

UID:啓動此進程的用戶

PID:此進程的父進程的PID

CCPU佔用百分比 cpuutilization

STIME:此進程的啓動時間,start time

TTY:在何種終端下啓動的此進程

TIME:此進程的累積運行時間

 

 

實例:樹形結構顯示進程

  • -H:以層級結構顯示進程的相關信息;

  • -F:顯示完整格式的進程信息;

[root@Linux_11 ~]# ps -eFH

UID        PID PPID  C    SZ  RSS PSR STIME TTY          TIMECMD

root         2    0  0     0    0   2 Dec25 ?        00:00:00 [kthreadd]

root         3    2  0     0    0   0 Dec25 ?        00:00:00   [migration/0]

root         4    2  0     0    0   0 Dec25 ?        00:00:00   [ksoftirqd/0]

root         5    2  0     0    0   0 Dec25 ?        00:00:00   [migration/0]

root         6    2  0     0    0   0 Dec25 ?        00:00:01   [watchdog/0]

root         7    2  0     0    0   1 Dec25 ?        00:00:00   [migration/1]

root         8    2  0     0    0   1 Dec25 ?        00:00:00   [migration/1]

相關說明如下:

PSR:運行在哪顆CPU

 

 

實例:指定字段名來顯示進程

常用的字段值有:pid, ni, pri, psr, pcpu, stat, comm, tty, ppid, rtprio

ninice值;

prioritypriority, 優先級;

rtprioreal time priority,實時優先級

 

提示:

  • field1, field2,...:自定義要顯示的字段列表,以逗號分隔;

  • o必須寫在後面

  • 字段不分大小寫

 

[root@Linux_11 ~]# ps axo pid,command

PID COMMAND

1 /sbin/init

2 [kthreadd]

3 [migration/0]

4 [ksoftirqd/0]

5 [migration/0]

6 [watchdog/0]

7 [migration/1]

8 [migration/1]

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章