[20230323]ps命令檢視thread.txt

lfree發表於2023-03-27

[20230323]ps命令檢視thread.txt

--//前一段時間遇到的問題,ps -fp <pid> ,沒有查詢到對應程式,當時有點蒙.
--//現在想想可能對應的是執行緒,不能透過這樣的方式查詢.應該加入-L引數.
--//看了一些檔案順便學習相關內容.

$ ps -o nlwp,pid,lwp,user,args  -u grid | awk '$1>1 { print $0}'
NLWP   PID   LWP USER     COMMAND
  28  8870  8870 grid     /u01/app/11.2.0/grid/bin/oraagent.bin
   9 11035 11035 grid     /u01/app/11.2.0/grid/bin/gipcd.bin
   4 11037 11037 grid     /u01/app/11.2.0/grid/bin/mdnsd.bin
  18 11163 11163 grid     /u01/app/11.2.0/grid/bin/ocssd.bin
  17 11949 11949 grid     /u01/app/11.2.0/grid/bin/evmd.bin
   6 12285 12285 grid     /u01/app/11.2.0/grid/bin/gpnpd.bin
  54 14183 14183 grid     /u01/app/11.2.0/grid/jdk/bin/java -server -Xcheck:jni -Xms128M -Xmx384M
                          -Djava.awt.headless=true -Ddisable.checkForUpdate=true -Dstdstream.filesize=100 -Dstdstream.filenumber=10
                          -DTRACING.ENABLED=false -Doracle.wlm.dbwlmlogger.logging.level=INFO -Dport.rmi=23792 -jar
                          /u01/app/11.2.0/grid/oc4j/j2ee/home/oc4j.jar -config /u01/app/11.2.0/grid/oc4j/j2ee/home/OC4J_DBWLM_config/server.xml
                          -out /u01/app/11.2.0/grid/oc4j/j2ee/home/log/oc4j.out -err /u01/app/11.2.0/grid/oc4j/j2ee/home/log/oc4j.err
  23 15261 15261 grid     /u01/app/11.2.0/grid/bin/oraagent.bin
   3 24695 24695 grid     /u01/app/11.2.0/grid/bin/tnslsnr dbrayw -inherit
  16 30995 30995 grid     /u01/app/11.2.0/grid/opmn/bin/ons -d
   3 31146 31146 grid     /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
   3 31152 31152 grid     /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
   3 31268 31268 grid     /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
--//nlwp等於對應執行緒的數量.

$ ps -o nlwp,pid,lwp,user,args  -u oracle | awk '$1>1 { print $0}'
NLWP   PID   LWP USER     COMMAND
  16 15415 15415 oracle   /u01/app/11.2.0/grid/bin/oraagent.bin
--//奇怪怎麼兩個使用者oracle,grid下都有這個程式執行.

--//在測試環境檢視:
$ ps -o nlwp,pid,lwp,args -e | awk '$1>1 { print $0}'
NLWP   PID   LWP COMMAND
   2  4049  4049 auditd
   2  4051  4051 /sbin/audispd
   5  4384  4384 automount --pid-file /var/run/autofs.pid
   6  9290  9290 /sbin/rsyslogd -i /var/run/rsyslogd.pid -c3 -x
   3 44997 44997 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit

--//如果要想顯示全部執行緒,可以加入-L引數加上grep過濾就可以得到程式號.
$ ps -eLf | grep "tnslsn[r]"
oracle   44997     1 44997  0    3 Mar20 ?        00:10:23 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   44997     1 44998  0    3 Mar20 ?        00:00:05 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   44997     1 44999  0    3 Mar20 ?        00:00:00 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
--//第5列3表示執行緒數量.

$ ps -eLf | grep "rsyslog[d]"
root      9290     1  9290  0    6  2021 ?        00:00:00 /sbin/rsyslogd -i /var/run/rsyslogd.pid -c3 -x
root      9290     1 33554  0    6 Mar11 ?        00:00:00 /sbin/rsyslogd -i /var/run/rsyslogd.pid -c3 -x
root      9290     1 33555  0    6 Mar11 ?        00:00:01 /sbin/rsyslogd -i /var/run/rsyslogd.pid -c3 -x
root      9290     1 33556  0    6 Mar11 ?        00:00:23 /sbin/rsyslogd -i /var/run/rsyslogd.pid -c3 -x
root      9290     1 33557  0    6 Mar11 ?        00:00:00 /sbin/rsyslogd -i /var/run/rsyslogd.pid -c3 -x
root      9290     1  3272  0    6 10:35 ?        00:00:00 /sbin/rsyslogd -i /var/run/rsyslogd.pid -c3 -x

--//還可以執行如下:
$ ps -Lfp 44997
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
oracle   44997     1 44997  0    3 Mar20 ?        00:10:24 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   44997     1 44998  0    3 Mar20 ?        00:00:12 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   44997     1 44999  0    3 Mar20 ?        00:00:00 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit

--//透過pstack觀察.
$ pstack 44997
Thread 3 (Thread 0x7f23ea92c940 (LWP 44998)):
#0  0x000000379909a221 in nanosleep () from /lib64/libc.so.6
#1  0x000000379909a044 in sleep () from /lib64/libc.so.6
#2  0x00007f23ebe1398a in ons_receivethread () from /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libons.so
#3  0x000000379a00683d in start_thread () from /lib64/libpthread.so.0
#4  0x00000037990d503d in clone () from /lib64/libc.so.6
Thread 2 (Thread 0x7f23ea8eb940 (LWP 44999)):
#0  0x000000379a00b019 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007f23ebe13289 in ons_recvthread_getsocket () from /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libons.so
#2  0x00007f23ebe14ef2 in ons_sendthread () from /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libons.so
#3  0x000000379a00683d in start_thread () from /lib64/libpthread.so.0
#4  0x00000037990d503d in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x7f23ebc096e0 (LWP 44997)):
#0  0x00000037990cc116 in poll () from /lib64/libc.so.6
#1  0x00007f23ee3a62bd in ntevpque () from /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libclntsh.so.11.1
#2  0x00007f23ee3a5f20 in ntevque () from /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libclntsh.so.11.1
#3  0x00007f23ee3a1d71 in nsevwait () from /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libclntsh.so.11.1
#4  0x000000000040842e in nsglma ()
#5  0x00000000004063cb in main ()

--//如果檢視執行緒執行如下.
$ pstack 44998
Thread 1 (process 44998):
#0  0x000000379909a221 in nanosleep () from /lib64/libc.so.6
#1  0x000000379909a044 in sleep () from /lib64/libc.so.6
#2  0x00007f23ebe1398a in ons_receivethread () from /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libons.so
#3  0x000000379a00683d in start_thread () from /lib64/libpthread.so.0
#4  0x00000037990d503d in clone () from /lib64/libc.so.6
--//缺點不知道程式號.

--//另外執行緒有1個特點,如果你kill其中1個執行緒,整個程式也會kill掉,測試看看.
$ kill -URG 44998
$ ps -Lfp 44997
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
oracle   44997     1 44997  0    3 Mar20 ?        00:10:24 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   44997     1 44998  0    3 Mar20 ?        00:00:12 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   44997     1 44999  0    3 Mar20 ?        00:00:00 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit

$ kill -9 44998
$ ps -Lfp 4499
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD

$ ps -eLf | grep "tnslsn[r]"
--//沒有任何輸出.

$ lsnrctl start
....

$ ps -eLf | grep "tnslsn[r]"
oracle   34299     1 34299  0    3 10:07 ?        00:00:00 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   34299     1 34300  0    3 10:07 ?        00:00:00 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle   34299     1 34301  0    3 10:07 ?        00:00:00 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2941980/,如需轉載,請註明出處,否則將追究法律責任。

相關文章