ps查看线程所在的cpu + pstack 线程+ strace 线程

摘要:
00:00:00[kni_vEth0_0]1根3281720800-0kni_th05:12?
[root@localhost kni]# ps -elf | grep kni
4 R root      32791  27964 99  80   0 - 8410299 -    05:12 pts/0    00:00:14 ./examples/kni/build/app/kni -c 0xFFFFF -n 4 -- -P -p 0x1 --config=(0,1,2,3,4)
1 S root      32813      2  0  80   0 -     0 kni_th 05:12 ?        00:00:00 [kni_vEth0_0]
1 S root      32817      2  0  80   0 -     0 kni_th 05:12 ?        00:00:00 [kni_vEth0_1]
[root@localhost kni]# ps -mo pid,tid,%cpu,psr -p  32813
   PID    TID %CPU PSR
 32813      -  0.1   -
     -  32813  0.1   3
[root@localhost kni]# ps -mo pid,tid,%cpu,psr -p  32817
   PID    TID %CPU PSR
 32817      -  0.4   -
     -  32817  0.4   4
 
[root@localhost kni]# ps -mo pid,tid,%cpu,psr -p  32791
   PID    TID %CPU PSR
 32791      -  298   -
     -  32791 99.6   0
     -  32792  0.0  60
     -  32793  0.0  20
     -  32794 99.3   1
     -  32795 99.4   2
     -  32796  0.0   3
     -  32797  0.0   4
     -  32798  0.0   5
     -  32799  0.0   6
     -  32800  0.0   7
     -  32801  0.0   8
     -  32802  0.0   9
     -  32803  0.0  10
     -  32804  0.0  11
     -  32805  0.0  12
     -  32806  0.0  13
     -  32807  0.0  14
     -  32808  0.0  15
     -  32809  0.0  16
     -  32810  0.0  17
     -  32811  0.0  18
     -  32812  0.0  19
[root@localhost kni]# 
[root@localhost kni]# ps -T -p  32791
   PID   SPID TTY          TIME CMD
 32791  32791 pts/0    00:05:29 kni
 32791  32792 pts/0    00:00:00 eal-intr-thread
 32791  32793 pts/0    00:00:00 rte_mp_handle
 32791  32794 pts/0    00:05:28 lcore-slave-1
 32791  32795 pts/0    00:05:29 lcore-slave-2
 32791  32796 pts/0    00:00:00 lcore-slave-3
 32791  32797 pts/0    00:00:00 lcore-slave-4
 32791  32798 pts/0    00:00:00 lcore-slave-5
 32791  32799 pts/0    00:00:00 lcore-slave-6
 32791  32800 pts/0    00:00:00 lcore-slave-7
 32791  32801 pts/0    00:00:00 lcore-slave-8
 32791  32802 pts/0    00:00:00 lcore-slave-9
 32791  32803 pts/0    00:00:00 lcore-slave-10
 32791  32804 pts/0    00:00:00 lcore-slave-11
 32791  32805 pts/0    00:00:00 lcore-slave-12
 32791  32806 pts/0    00:00:00 lcore-slave-13
 32791  32807 pts/0    00:00:00 lcore-slave-14
 32791  32808 pts/0    00:00:00 lcore-slave-15
 32791  32809 pts/0    00:00:00 lcore-slave-16
 32791  32810 pts/0    00:00:00 lcore-slave-17
 32791  32811 pts/0    00:00:00 lcore-slave-18
 32791  32812 pts/0    00:00:00 lcore-slave-19
[root@localhost ixgbe]# ps -Leo pid,tid,args:30,psr,comm | grep kni
 31347  31347 ./examples/kni/build/app/kni -   0 kni
 31347  31348 ./examples/kni/build/app/kni -  47 eal-intr-thread
 31347  31349 ./examples/kni/build/app/kni -  21 rte_mp_handle
 31347  31350 ./examples/kni/build/app/kni -   1 lcore-slave-1
 31347  31351 ./examples/kni/build/app/kni -   2 lcore-slave-2
 31347  31352 ./examples/kni/build/app/kni -   3 lcore-slave-3
 31347  31353 ./examples/kni/build/app/kni -   4 lcore-slave-4
 31347  31354 ./examples/kni/build/app/kni -   5 lcore-slave-5
 31347  31355 ./examples/kni/build/app/kni -   6 lcore-slave-6
 31347  31356 ./examples/kni/build/app/kni -   7 lcore-slave-7
 31347  31357 ./examples/kni/build/app/kni -   8 lcore-slave-8
 31347  31358 ./examples/kni/build/app/kni -   9 lcore-slave-9
 31347  31359 ./examples/kni/build/app/kni -  10 lcore-slave-10
 31347  31360 ./examples/kni/build/app/kni -  11 lcore-slave-11
 31347  31361 ./examples/kni/build/app/kni -  12 lcore-slave-12
 31347  31362 ./examples/kni/build/app/kni -  13 lcore-slave-13
 31347  31363 ./examples/kni/build/app/kni -  14 lcore-slave-14
 31347  31364 ./examples/kni/build/app/kni -  15 lcore-slave-15
 31347  31365 ./examples/kni/build/app/kni -  16 lcore-slave-16
 31347  31366 ./examples/kni/build/app/kni -  17 lcore-slave-17
 31347  31367 ./examples/kni/build/app/kni -  18 lcore-slave-18
 31347  31368 ./examples/kni/build/app/kni -  19 lcore-slave-19
 31370  31370 [kni_vEth0]                    125 kni_vEth0
 31676  31676 grep --color=auto kni           48 grep
[root@localhost ixgbe]# 
root@ubuntu:~# ps H -o 'tid comm' 42464
  TID COMMAND
42464 firecracker
42465 fc_api
42505 fc_vcpu 0
root@ubuntu:~# ps -T -p 42464
  PID  SPID TTY          TIME CMD
42464 42464 pts/2    00:00:00 firecracker
42464 42465 pts/2    00:00:00 fc_api
42464 42505 pts/2    00:00:01 fc_vcpu 0
root@ubuntu:~# 
2. ps 命令

-L参数显示进程,并尽量显示其LWP(线程ID)和NLWP(线程的个数)。

[root@jay-linux ~]# ps -eLf | grep qemu 
root     657 196 657  0 3 13:48 pts/1   00:00:00 qemu-sys -m 1024 -smp 2 
root     657 196 660  3 3 13:48 pts/1   00:00:26 qemu-sys -m 1024 -smp 2 
root     657 196 661  2 3 13:48 pts/1   00:00:19 qemu-sys -m 1024 -smp 2 
root     789  9799 10789  0 1 14:02 pts/0   00:00:00 grep --color=auto qemu 
上面命令查询结果的第二列为PID,第三列为PPID,第四列为LWP,第六列为NLWP。

另外,ps命令还可以查看线程在哪个CPU上运行,命令如下:

[root@jay-linux ~]# ps -eo ruser,pid,ppid,lwp,psr,args -L | grep qemu 
root     657 196 657   1 qemu-sys -hda smep-temp.qcow -m 1024 -smp 2 
root     657 196 660   1 qemu-sys -hda smep-temp.qcow -m 1024 -smp 2 
root     657 196 661   2 qemu-sys -hda smep-temp.qcow -m 1024 -smp 2 
root     834  9799 10834   1 grep --color=auto qemu 
其中,每一列依次为:用户ID,进程ID,父进程ID,线程ID,运行该线程的CPU的序号,命令行参数(包括命令本身)。
root@25a725e7599e:/# ps -u "$(id -u)" -o pid,user,mntns,command --sort mntns
  PID USER          MNTNS COMMAND
    1 root     4026531840 /sbin/init
    2 root     4026531840 [kthreadd]
    3 root     4026531840 [rcu_gp]
    4 root     4026531840 [rcu_par_gp]
    5 root     4026531840 [kworker/0:0-eve]
    6 root     4026531840 [kworker/0:0H]
    8 root     4026531840 [mm_percpu_wq]
    9 root     4026531840 [ksoftirqd/0]
   10 root     4026531840 [rcu_sched]
   11 root     4026531840 [migration/0]
   12 root     4026531840 [cpuhp/0]
   14 root     4026531840 [netns]
   15 root     4026531840 [oom_reaper]
   16 root     4026531840 [writeback]
   17 root     4026531840 [kcompactd0]
   18 root     4026531840 [kblockd]
   19 root     4026531840 [blkcg_punt_bio]
   20 root     4026531840 [kworker/0:1-eve]
   21 root     4026531840 [kswapd0]

方法一

先用ps -mp pid或者top -H查出线程pid。

然后strace -p pid追踪其中一个线程。

方法二

直接用strace -fp pid追踪进程下所有线

[root@localhost l2fwd2-rss]# ps -T -p 29765
   PID   SPID TTY          TIME CMD
 29765  29765 pts/1    00:13:14 l2fwd2
 29765  29766 pts/1    00:00:00 eal-intr-thread
 29765  29767 pts/1    00:00:00 rte_mp_handle
 29765  29768 pts/1    00:13:12 lcore-slave-8
 29765  29769 pts/1    00:13:12 lcore-slave-9
 29765  29770 pts/1    00:13:12 lcore-slave-10
[root@localhost l2fwd2-rss]# strace -p 29768
strace: Process 29768 attached
^Cstrace: Process 29768 detached
[root@localhost l2fwd2-rss]# pstack 29768
Thread 1 (process 29768):
#0  0x0000000000787168 in hinic_recv_pkts (rx_queue=0x13e4ba900, rx_pkts=0xffffb5ddcea0, nb_pkts=32) at /data1/dpdk-19.11/drivers/net/hinic/hinic_pmd_rx.c:956
#1  0x0000000000466c84 in rte_eth_rx_burst (nb_pkts=32, rx_pkts=0xffffb5ddcea0, queue_id=1, port_id=0) at /data1/dpdk-19.11/arm64-armv8a-linuxapp-gcc/include/rte_ethdev.h:4387
#2  main_loop (arg=<optimized out>) at /data1/dpdk-19.11/demo/l2fwd2-rss/main.c:1085
#3  0x0000000000593bc8 in eal_thread_loop (arg=0x0) at /data1/dpdk-19.11/lib/librte_eal/linux/eal/eal_thread.c:153
#4  0x0000ffffb6fe7d38 in start_thread (arg=0xffffb5ddd910) at pthread_create.c:309
#5  0x0000ffffb6f2f5f0 in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:91
[root@localhost l2fwd2-rss]# pstack 29769
Thread 1 (process 29769):
#0  0x000000000078717c in hinic_recv_pkts (rx_queue=0x13e47a900, rx_pkts=0xffffb55ccea0, nb_pkts=32) at /data1/dpdk-19.11/drivers/net/hinic/hinic_pmd_rx.c:966
#1  0x0000000000466c84 in rte_eth_rx_burst (nb_pkts=32, rx_pkts=0xffffb55ccea0, queue_id=0, port_id=1) at /data1/dpdk-19.11/arm64-armv8a-linuxapp-gcc/include/rte_ethdev.h:4387
#2  main_loop (arg=<optimized out>) at /data1/dpdk-19.11/demo/l2fwd2-rss/main.c:1085
#3  0x0000000000593bc8 in eal_thread_loop (arg=0x0) at /data1/dpdk-19.11/lib/librte_eal/linux/eal/eal_thread.c:153
#4  0x0000ffffb6fe7d38 in start_thread (arg=0xffffb55cd910) at pthread_create.c:309
#5  0x0000ffffb6f2f5f0 in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:91
[root@localhost l2fwd2-rss]#

免责声明:文章转载自《ps查看线程所在的cpu + pstack 线程+ strace 线程》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇一种简单有效的VBA源代码加密办法,支持64位宿主,适用于大部分VBA代码加密UML绘图工具——PlantUML下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Jumpserver实践

Jumpserver实践 提前准备好jumpserver服务端 source /opt/py3/bin/activate /opt/jumpserver/jms start -d # koko /opt/koko/koko -d /etc/init.d/guacd start sh /opt/tomcat9/bin/startup.sh # ngi...

使用Apple Configurator 2提取商店ipa or app文件

之前我们可以通过iTunes来提取商店的ipa文件, 但12.+版本以后这个功能就被拿掉了 目前可以借用Apple Configurator 2工具来实现 安装: 可以直接在App Store搜索安装 使用: 打开后可以看到已经连接的手机 选择一台已经安装过想要获取ipa软件的手机 进入手机详情界面后点击添加, 选择app 在弹出的搜索框中输入想要提...

GPG操作——签名验证

问题描述: 可能大家都遇到过软件在下载过程中由于网络原因导致下载的软件体积与实际软件体积不符。最常见的办法是对待下载文件附加一个摘要文件。这种做法比较常见,也比较容易实现。但是,还是会有一个问题:如果我篡改了网站,改变了文件的内容,并对该文件做了一次摘要,替换了原有的摘要文件。那用户下载的文件就失去了摘要验证的意义。如何避免这种问题呢? 解决方案: 软件提...

深入理解二维码生成尺寸

详细了解二维码的原理,CSDN这两篇博客不错: 转自MachineChen的博客:http://blog.csdn.net/u012611878/article/details/53167009 转自琦小虾的博客:https://blog.csdn.net/ajianyingxiaoqinghan/article/details/78837864 我理解的...

一步一步实现iOS应用PUSH功能

1. push原理 iOS push 工作机制可以用下图简要概括 Provider:应用自己的服务器; APNS:Apple Push Notification Service的简称,苹果的PUSH服务器; push的主要工作流程是: iOS设备连接网络后,会自动与APNS保持类似TCP的长链接,等待APNS推送消息的到来; 应用启动时注册消息...

【react+antd】前端读取本地文件内容(txt)

场景:xxx血压计测量数据之后,需要将测量的数据直接显示在pc后台管理平台相应的表格中 准备:一台xxx血压计,数据线,相关血压计桌面软件,pc 血压计相关说明:测量时,将数据线和pc连接,打开血压计桌面软件,点击连接设备,连接成功,开始测量,测量完成,桌面软件会显示相应的值:比如 收缩压 舒张压 心率 脉搏等,数据会存到本地的某个文件下,txt文本形式,...