[Linux] ps (process status) 指令 – 檢視多執行緒

Intro

ps (process status)

pstree


通用

$ ps aux

Grep應用:

$ ps aux | grep php
$ ps aux | egrep "php|PID"
$ ps aux | { head -1; grep "php";}

head & tail

$ ps aux | head -n 5
$ ps aux | tail-n 5
$ ps aux | { head -n 1;tail -n 5;}

多執行緒

pstree

樹狀processes/threads結構清單

$ pstree -ap
$ pstree -ap | grep go

ps

加入-L顯示多執行緒、-f為完整格式:

$ ps ax -Lf
UID        PID  PPID   LWP  C NLWP STIME TTY      STAT   TIME CMD
root      4403  4402  4403  0    1 17:14 pts/1    S      0:00 su
root      4404  4403  4404  0    1 17:14 pts/1    S      0:00 bash
root      5306  4404  5306  0    7 17:22 pts/1    Sl+    0:00 node web.js
root      5306  4404  5307  0    7 17:22 pts/1    Sl+    0:00 node web.js
root      5306  4404  5308  0    7 17:22 pts/1    Sl+    0:00 node web.js
root      5306  4404  5309  0    7 17:22 pts/1    Sl+    0:00 node web.js
root      5306  4404  5310  0    7 17:22 pts/1    Sl+    0:00 node web.js
root      5306  4404  5311  0    7 17:22 pts/1    Sl+    0:00 node web.js
root      5306  4404  5312  0    7 17:22 pts/1    Sl+    0:00 node web.js

PID:程序ID、PPID:父程序ID、LWP:執行緒ID、NLWP:Number of LWP

PSR

psr也就是cpuid,可得知程式在哪個Core上執行,文件可以透過man ps查看:

   psr        PSR     processor that process is currently assigned to.

PSR必須使用-o客製格式輸出:

$ ps a -o user,pid,ppid,lwp,nlwp,psr,args -L
USER       PID  PPID   LWP NLWP PSR COMMAND
nick_ts+  3998  3997  3998    1   1 -bash
nick_ts+  4029  3998  4029    8   2 go run web.go
nick_ts+  4029  3998  4030    8   0 go run web.go
nick_ts+  4029  3998  4031    8   0 go run web.go
nick_ts+  4029  3998  4032    8   2 go run web.go
nick_ts+  4029  3998  4033    8   1 go run web.go
nick_ts+  4029  3998  4034    8   1 go run web.go
nick_ts+  4029  3998  4082    8   0 go run web.go
nick_ts+  4029  3998  4083    8   1 go run web.go

Leave a Reply

Your email address will not be published. Required fields are marked *