linux查看线程/进程/调用栈信息-pstack/pstree

本文通过使用pstree、ps及pstack等命令,详细分析了一个名为ad_preprocess的进程及其所启动的多个子线程的情况,展示了如何查看进程树、获取进程详细信息以及追踪线程的具体状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

¥ pstree -p work | grep ad
sshd(22669)---bash(22670)---ad_preprocess(4551)-+-{ad_preprocess}(4552)
                                                |-{ad_preprocess}(4553)
                                                |-{ad_preprocess}(4554)
                                                |-{ad_preprocess}(4555)
                                                |-{ad_preprocess}(4556)
                                                `-{ad_preprocess}(4557)


work为工感化户,-p为显示过程辨认码,ad_preprocess共启动了6个子线程,加上主线程共7个线程

2. ps -Lf

¥ ps -Lf 4551
UID        PID  PPID   LWP  C NLWP STIME TTY      STAT   TIME CMD
work      4551 22670  4551  2    7 16:30 pts/2    Sl+    0:02 ./ad_preprocess
work      4551 22670  4552  0    7 16:30 pts/2    Sl+    0:00 ./ad_preprocess
work      4551 22670  4553  0    7 16:30 pts/2    Sl+    0:00 ./ad_preprocess
work      4551 22670  4554  0    7 16:30 pts/2    Sl+    0:00 ./ad_preprocess
work      4551 22670  4555  0    7 16:30 pts/2    Sl+    0:00 ./ad_preprocess
work      4551 22670  4556  0    7 16:30 pts/2    Sl+    0:00 ./ad_preprocess
work      4551 22670  4557  0    7 16:30 pts/2    Sl+    0:00 ./ad_preprocess

过程共启动了7个线程

3. pstack

pstack显示每个过程的栈跟踪

¥ pstack 4551
Thread 7 (Thread 1084229984 (LWP 4552)):
#0  0 x000000302afc63dc in epoll_wait () /lib64/tls/libc.so.6
#1  0 x00000000006f0730 in ub::EPollEx::poll ()
#2  0 x00000000006f172a in ub::NetReactor::callback ()
#3  0 x00000000006fbbbb in ub::UBTask::CALLBACK ()
#4  0 x000000302b80610a in start_thread () /lib64/tls/libpthread.so.0
#5  0 x000000302afc6003 in clone () /lib64/tls/libc.so.6
#6  0 x0000000000000000 in ?? ()
Thread 6 (Thread 1094719840 (LWP 4553)):
#0  0 x000000302afc63dc in epoll_wait () /lib64/tls/libc.so.6
#1  0 x00000000006f0730 in ub::EPollEx::poll ()
#2  0 x00000000006f172a in ub::NetReactor::callback ()
#3  0 x00000000006fbbbb in ub::UBTask::CALLBACK ()
#4  0 x000000302b80610a in start_thread () /lib64/tls/libpthread.so.0
#5  0 x000000302afc6003 in clone () /lib64/tls/libc.so.6
#6  0 x0000000000000000 in ?? ()
Thread 5 (Thread 1105209696 (LWP 4554)):
#0  0 x000000302b80baa5 in __nanosleep_nocancel ()
#1  0 x000000000079e758 in comcm::ms_sleep ()
#2  0 x00000000006c8581 in ub::UbClientManager::healthyCheck ()
#3  0 x00000000006c8471 in ub::UbClientManager::start_healthy_check ()
#4  0 x000000302b80610a in start_thread () /lib64/tls/libpthread.so.0
#5  0 x000000302afc6003 in clone () /lib64/tls/libc.so.6
#6  0 x0000000000000000 in ?? ()
Thread 4 (Thread 1115699552 (LWP 4555)):
#0  0 x000000302b80baa5 in __nanosleep_nocancel ()
#1  0 x0000000000482b0e in armor::armor_check_thread ()
#2  0 x000000302b80610a in start_thread () /lib64/tls/libpthread.so.0
#3  0 x000000302afc6003 in clone () /lib64/tls/libc.so.6
#4  0 x0000000000000000 in ?? ()
Thread 3 (Thread 1126189408 (LWP 4556)):
#0  0 x000000302af8f1a5 in __nanosleep_nocancel () /lib64/tls/libc.so.6
#1  0 x000000302af8f010 in sleep () /lib64/tls/libc.so.6
#2  0 x000000000044c972 in Business_config_manager::run ()
#3  0 x0000000000457b83 in Thread::run_thread ()
#4  0 x000000302b80610a in start_thread () /lib64/tls/libpthread.so.0
#5  0 x000000302afc6003 in clone () /lib64/tls/libc.so.6
#6  0 x0000000000000000 in ?? ()
Thread 2 (Thread 1136679264 (LWP 4557)):
#0  0 x000000302af8f1a5 in __nanosleep_nocancel () /lib64/tls/libc.so.6
#1  0 x000000302af8f010 in sleep () /lib64/tls/libc.so.6
#2  0 x00000000004524bb in Process_thread::sleep_period ()
#3  0 x0000000000452641 in Process_thread::run ()
#4  0 x0000000000457b83 in Thread::run_thread ()
#5  0 x000000302b80610a in start_thread () /lib64/tls/libpthread.so.0
#6  0 x000000302afc6003 in clone () /lib64/tls/libc.so.6
#7  0 x0000000000000000 in ?? ()
Thread 1 (Thread 182894129792 (LWP 4551)):
#0  0 x000000302af8f1a5 in __nanosleep_nocancel () /lib64/tls/libc.so.6
#1  0 x000000302af8f010 in sleep () /lib64/tls/libc.so.6
#2  0 x0000000000420d79 in Ad_preprocess::run ()
#3  0 x0000000000450ad0 in main ()巴尔扎克


install -d -m0755 /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages ipkg-build -c -o 0 -g 0 /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-cn913x/gdb /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages Packaged contents of /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-cn913x/gdb into /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages/gdb_8.1-1_cn913x.ipk rm -rf /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb mkdir -p /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/stamp /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb install -d -m0755 /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/bin /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/sbin/ install -m0755 /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-install/usr/bin/gdb /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/bin/ install -m0755 ./files/usr/sbin/pstack /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/sbin/ SHELL= /home/felix/mydisk/enterprise_gateway/staging_dir/host/bin/flock /home/felix/mydisk/enterprise_gateway/tmp/.root-copy.flock -c 'cp -fpR /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/. /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/' rm -rf /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb touch /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/stamp/.gdb_installed if [ -f /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install.clean ]; then rm -f /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install.clean; fi; echo "gdb" >> /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install WARNING: skipping gdbserver -- package not selected make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/package/devel/gdb' make[2]: Leaving directory '/home/felix/mydisk/enterprise_gateway' package/Makefile:190: recipe for target '/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile' failed make[1]: *** [/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile] Error 2 make[1]: Leaving directory '/home/felix/mydisk/enterprise_gateway' /home/felix/mydisk/enterprise_gateway/include/toplevel.mk:171: recipe for target 'world' failed make: *** [world] Error 2
最新发布
07-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值