linux下查看跟踪线程

假设进程为my_process:

# ps -ef|grep my_process
root     10001  3322  0 14:05 ?        00:01:19 my_process
root     26844 23970  0 17:12 pts/0    00:00:00 grep my_process

1) 通过ps命令查看线程,SPID是线程ID,STAT是线程状态
# ps H -T -p 10001
  PID  SPID TTY      STAT   TIME COMMAND
10001 10001 ?        Sl     0:00 my_process
10001 10023 ?        Sl     0:00 my_process
10001 10229 ?        Sl     0:00 my_process
10001 10282 ?        Sl     0:04 my_process
10001 10283 ?        Sl     0:02 my_process
10001 10284 ?        Sl     0:01 my_process
10001 10285 ?        Sl     0:02 my_process
10001 10286 ?        Sl     0:04 my_process
10001 10287 ?        Sl     0:04 my_process
10001 10288 ?        Sl     0:00 my_process
10001 10289 ?        Sl     0:00 my_process
10001 10290 ?        Sl     0:00 my_process


2) 通过top命令查看线程资源占用,PID是线程ID
# top -H -p 10001
top - 17:14:54 up 9 days, 21:54,  2 users,  load average: 0.07, 0.07, 0.05
Threads:  51 total,   0 running,  51 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.7 sy,  0.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  4046852 total,  2947116 free,   621440 used,   478296 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  2842320 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                                                                                                 
10300 root     -46   0 2048420 422828  19784 S  0.3 10.4   0:01.15 my_process                                                                                                                                                                    
10302 root     -98   0 2048420 422828  19784 S  0.3 10.4   0:03.01 my_process                                                                                                                                                                    
10332 root     -66   0 2048420 422828  19784 S  0.3 10.4   0:09.63 my_process                                                                                                                                                                    
10001 root     -97   0 2048420 422828  19784 S  0.0 10.4   0:00.30 my_process                                                                                                                                                                    
10023 root     -92   0 2048420 422828  19784 S  0.0 10.4   0:00.00 my_process                                                                                                                                                                    
10229 root     -11   0 2048420 422828  19784 S  0.0 10.4   0:00.29 my_process                                                                                                                                                                    
10282 root     -96   0 2048420 422828  19784 S  0.0 10.4   0:05.03 my_process                                                                                                                                                                    
10283 root     -97   0 2048420 422828  19784 S  0.0 10.4   0:02.14 my_process                                                                                                                                                                    
10284 root     -34   0 2048420 422828  19784 S  0.0 10.4   0:01.82 my_process                                                                                                                                                                    
10285 root     -34   0 2048420 422828  19784 S  0.0 10.4   0:02.32 my_process                                                                                                                                                                    

3) 通过pstack查看线程back trace, 需要-g编译包含符号表,仅适用于32位系统。   

4)通过strace跟踪线程系统调用

strace -p pid 其中pid为线程ID,可以跟踪某个线程

strace -fp pid其中pid为进程ID,可以跟踪该进程的所有线程        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值