ps命令實例講解 查看線程信息

1.ps -e:-e用於顯示所有進程

[root@supersun.biz ~]#ps -e
PID TTY TIME CMD
1 ? 00:00:00 init
2 ? 00:00:00 migration/0
3 ? 00:00:00 ksoftirqd/0
4 ? 00:00:00 watchdog/0
5 ? 00:00:00 events/0

域定義:

PID 進程ID
TTY 與進程關聯的終端
TIME 進程使用CPU累計時間
CMD 執行文件的名稱

2.ps -ef:-f選項定義爲full-format listing

[root@supersun.biz ~]#ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 08:31 ? 00:00:00 init [5]
root 2 1 0 08:31 ? 00:00:00 [migration/0]
root 3 1 0 08:31 ? 00:00:00 [ksoftirqd/0]
root 4 1 0 08:31 ? 00:00:00 [watchdog/0]

域定義:
UID 用戶ID
C CPU利用率,以整數表示。
STIME 進程的啓動時間

3.ps -eF:-F選項添加了進程使用內存方面的一些信息

  • 測試了一下,該選項在AIX下是輸出格式定製選項,同-o選項。
[root@supersun ~]# ps -eF
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
root 1 0 0 508 684 1 Nov29 ? 00:00:00 init [5]
root 2 1 0 0 0 0 Nov29 ? 00:00:00 [migration/0]
root 3 1 0 0 0 0 Nov29 ? 00:00:00 [ksoftirqd/0]
root 4 1 0 0 0 0 Nov29 ? 00:00:00 [watchdog/0]
root 5 1 0 0 0 1 Nov29 ? 00:00:00 [migration/1]
root 6 1 0 0 0 1 Nov29 ? 00:00:00 [ksoftirqd/1]
root 7 1 0 0 0 1 Nov29 ? 00:00:00 [watchdog/1]

SZ 進程用到的swap的量,這是一個粗略計算;
RSS 駐留內存大小
PSR 進程使用的處理器,在多處理器上可以體現出來,如下面的兩個進程使用的不同的處理器(超線程的也算):

4.ps -eLf:-L用於顯示線程

  • 在AIX下-L選項需要後跟PID才行
[root@supersun.biz ~]#ps -eLf
UID PID PPID LWP C NLWP STIME TTY TIME CMD
root 1 0 1 0 1 08:31 ? 00:00:00 init [5]
root 2 1 2 0 1 08:31 ? 00:00:00 [migration/0]
root 2233 2228 2233 3 8 08:35 ? 00:04:50 /root/firefox/firefox-bin
root 2233 2228 2271 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin
root 2233 2228 2272 0 8 08:36 ? 00:00:01 /root/firefox/firefox-bin
root 2233 2228 2277 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin
root 2233 2228 2278 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin
root 2233 2228 2279 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin

LWP light weight process ID 可以稱其爲線程ID。
NLWP 進程中的線程數number of lwps (threads) in the process。

5.ps -ejH:顯示進程樹

[root@supersun.biz ~]#ps -ejH
PID PGID SID TTY TIME CMD
1 1 1 ? 00:00:00 init
2 1 1 ? 00:00:00 migration/0
3 1 1 ? 00:00:00 ksoftirqd/0
4 1 1 ? 00:00:00 watchdog/0
5 1 1 ? 00:00:00 events/0
6 1 1 ? 00:00:00 khelper
7 1 1 ? 00:00:00 kthread
10 1 1 ? 00:00:00 kblockd/0
11 1 1 ? 00:00:00 kacpid
86 1 1 ? 00:00:00 cqueue/0
89 1 1 ? 00:00:00 khubd

SID 即session ID
F即flag,其值有:
1 forked but didn't exec
4 used super-user privileges

S即STAT,其值有:
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.

參考:

ps命令實例講解 查看線程信息
https://www.cnblogs.com/shijingxiang/articles/4599281.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章