系统相关
首页 > 系统相关> > linux:查看线程的常用命令 (centos 8)

linux:查看线程的常用命令 (centos 8)

作者:互联网

一,pidstat 查看某个进程下的所有线程

例:
[lhdop@blog ~]$ pidstat -t -p 20756
Linux 4.18.0-80.11.2.el8_0.x86_64 (blog)        03/20/2022      _x86_64_        (4 CPU)
 
01:38:44 PM   UID      TGID       TID    %usr %system  %guest   %wait    %CPU   CPU  Command
01:38:44 PM  1000     20756         -    0.00    0.00    0.00    0.00    0.00     1  java
01:38:44 PM  1000         -     20756    0.00    0.00    0.00    0.00    0.00     1  |__java
01:38:44 PM  1000         -     20757    0.00    0.00    0.00    0.00    0.00     0  |__java
01:38:44 PM  1000         -     20758    0.00    0.00    0.00    0.00    0.00     1  |__GC Thread#0
01:38:44 PM  1000         -     20759    0.00    0.00    0.00    0.00    0.00     2  |__G1 Main Marker
01:38:44 PM  1000         -     20760    0.00    0.00    0.00    0.00    0.00     0  |__G1 Conc#0
01:38:44 PM  1000         -     20761    0.00    0.00    0.00    0.00    0.00     1  |__G1 Refine#0
01:38:44 PM  1000         -     20762    0.00    0.00    0.00    0.00    0.00     3  |__G1 Young RemSet
01:38:44 PM  1000         -     20763    0.00    0.00    0.00    0.00    0.00     2  |__VM Thread
01:38:44 PM  1000         -     20764    0.00    0.00    0.00    0.00    0.00     3  |__Reference Handl
01:38:44 PM  1000         -     20765    0.00    0.00    0.00    0.00    0.00     1  |__Finalizer
01:38:44 PM  1000         -     20766    0.00    0.00    0.00    0.00    0.00     1  |__Signal Dispatch
01:38:44 PM  1000         -     20767    0.00    0.00    0.00    0.00    0.00     0  |__Service Thread
…

参数说明:

 -t     Also display statistics for threads associated with selected tasks.

              This option adds the following values to the reports:

              TGID
                     The identification number of the thread group leader.

              TID
                     The identification number of the thread being monitored.

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,top查看某个进程下的线程:

[lhdop@blog ~]$ top -H -p 20756
top - 21:33:13 up 800 days, 11:29,  3 users,  load average: 0.05, 0.23, 0.46
Threads:  44 total,   0 running,  44 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.7 us,  0.1 sy,  0.0 ni, 98.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15355.3 total,    406.0 free,   2331.6 used,  12617.6 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  12695.1 avail Mem
 
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
20756 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.00 java
20757 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:04.29 java
20758 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.16 GC Thread#0
20759 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.00 G1 Main Marker
20760 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.18 G1 Conc#0
20761 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.04 G1 Refine#0
20762 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:14.18 G1 Young RemSet
20763 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:02.24 VM Thread
20764 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.00 Reference Handl
20765 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.00 Finalizer
20766 lhdop     20   0 7766336 354944  28800 S   0.0   2.3   0:00.00 Signal Dispatch
… 
参数说明:
       -H  :Threads-mode operation
            Instructs top to display individual threads.  Without this command-line option a summation of all threads in each  process  is  shown. 
Later this can be changed with the `H' interactive command.
说明:top默认显示一屏的内容, 如果用top查看某个进程下的所有线程,可以加参数 -b

三,ps查看线程:

[lhdop@blog ~]$ ps -T -p 20756
  PID  SPID TTY          TIME CMD
20756 20756 ?        00:00:00 java
20756 20757 ?        00:00:04 java
20756 20758 ?        00:00:00 GC Thread#0
20756 20759 ?        00:00:00 G1 Main Marker
20756 20760 ?        00:00:00 G1 Conc#0
20756 20761 ?        00:00:00 G1 Refine#0
20756 20762 ?        00:00:14 G1 Young RemSet
20756 20763 ?        00:00:02 VM Thread
20756 20764 ?        00:00:00 Reference Handl
20756 20765 ?        00:00:00 Finalizer
20756 20766 ?        00:00:00 Signal Dispatch
20756 20767 ?        00:00:02 Service Thread
20756 20768 ?        00:00:12 C2 CompilerThre
20756 20769 ?        00:00:04 C1 CompilerThre
20756 20770 ?        00:00:00 Sweeper thread
20756 20771 ?        00:00:00 Notification Th
20756 20772 ?        00:00:34 VM Periodic Tas
20756 20773 ?        00:00:00 Common-Cleaner
20756 20775 ?        00:00:00 GC Thread#1
20756 20776 ?        00:00:00 GC Thread#2
20756 20778 ?        00:00:00 GC Thread#3
20756 20781 ?        00:00:00 G1 Refine#1
20756 20782 ?        00:02:44 Log4j2-TF-10-As
...
参数说明:
-T     Show threads, possibly with SPID column.

四,查看linux的版本:

[lhdop@blog ~]$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
 
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8" 

 

标签:00,centos,0.0,0.00,44,线程,常用命令,lhdop,20756
来源: https://www.cnblogs.com/architectforest/p/16061970.html