pstack使用总结
概念
打印正在运行的进程的栈跟踪信息。常用来定位进程挂起的位置。
命令
# :进程id
pstack <process-id>
实例
1)查看redis进程id
[root@localhost ~]# ps -aux | grep redis
root 1149 0.1 0.4 163156 4480 ? Ssl 16:42 0:00 /usr/local/redis/bin/redis-server 0.0.0.0:6379
root 3121 0.0 0.0 112828 988 pts/0 R+ 16:43 0:00 grep --color=auto redis
2)查看进程的线程信息
使用"top -Hp 进程id"的方式查看进程中包含的线程基本信息。
[root@localhost ~]# top -H -p 1149top - 16:53:17 up 11 min, 2 users, load average: 0.00, 0.11, 0.13
Threads: 5 total, 0 running, 5 sleeping, 0 stopped, 0 zombie
%Cpu(s): 21.0 us, 6.1 sy, 0.0 ni, 72.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 995672 total, 185052 free, 484332 used, 326288 buff/cache
KiB Swap: 2097148 total, 1707004 free, 390144 used. 336520 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1149 root 20 0 163156 4824 504 S 0.3 0.5 0:00.66 redis-server 1171 root 20 0 163156 4824 504 S 0.0 0.5 0:00.00 bio_close_file 1172 root 20 0 163156 4824 504 S 0.0 0.5 0:00.00 bio_aof_fsync 1173 root 20 0 163156 4824 504 S 0.0 0.5 0:00.00 bio_lazy_free 1174 root 20 0 163156 4824 504 S 0.0 0.5 0:00.00 jemalloc_bg_thd
3)使用pstack查看信息
同gdb中**“thread apply all bt”**
[root@localhost ~]# pstack 1149
Thread 5 (Thread 0x7f1a97cbd700 (LWP 1171)):
#0 0x00007f1a9ef41a35 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x00000000004bc7a2 in bioProcessBackgroundJobs (arg=0x0) at bio.c:215
#2 0x00007f1a9ef3dea5 in start_thread () from /lib64/libpthread.so.0
#3 0x00007f1a9ec66b0d in clone () from /lib64/libc.so.6
Thread 4 (Thread 0x7f1a974bc700 (LWP 1172)):
#0 0x00007f1a9ef41a35 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x00000000004bc7a2 in bioProcessBackgroundJobs (arg=0x1) at bio.c:215
#2 0x00007f1a9ef3dea5 in start_thread () from /lib64/libpthread.so.0
#3 0x00007f1a9ec66b0d in clone () from /lib64/libc.so.6
Thread 3 (Thread 0x7f1a96cbb700 (LWP 1173)):
#0 0x00007f1a9ef41a35 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x00000000004bc7a2 in bioProcessBackgroundJobs (arg=0x2) at bio.c:215
#2 0x00007f1a9ef3dea5 in start_thread () from /lib64/libpthread.so.0
#3 0x00007f1a9ec66b0d in clone () from /lib64/libc.so.6
Thread 2 (Thread 0x7f1a964ba700 (LWP 1174)):
#0 0x00007f1a9ef41a35 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x0000000000546da8 in background_thread_sleep (tsdn=, interval=, info=0x7f1a9e80a940) at src/background_thread.c:232
#2 background_work_sleep_once (ind=0, info=, tsdn=0x7f1a964b8e60) at src/background_thread.c:307
#3 background_thread0_work (tsd=0x7f1a964b8e60) at src/background_thread.c:452
#4 background_work (ind=, tsd=0x7f1a964b8e60) at src/background_thread.c:490
#5 background_thread_entry (ind_arg=) at src/background_thread.c:522
#6 0x00007f1a9ef3dea5 in start_thread () from /lib64/libpthread.so.0
#7 0x00007f1a9ec66b0d in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x7f1a9fa65fc0 (LWP 1149)):
#0 0x00007f1a9ec670e3 in epoll_wait () from /lib64/libc.so.6
#1 0x000000000045680 in aeApiPoll (tvp=0x7ffcb1cb3700, eventLoop=0x7f1a9e62a0f0) at ae_epoll.c:113
#2 aeProcessEvents (eventLoop=eventLoop@entry=0x7f1a9e62a0f0, flags=flags@entry=27) at ae.c:404
#3 0x0000000000445b1d in aeMain (eventLoop=0x7f1a9e62a0f0) at ae.c:496
#4 0x0000000000441d11 in main (argc=2, argv=0x7ffcb1cb38c8) at server.c:7167
[root@localhost ~]#
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!