1.命令作用
打印正在运行的进程的堆栈跟踪(print a stack trace of a running process);
此命令可显示每个进程的栈跟踪。pstack 命令必须由相应进程的属主或 root 运行。可以使用 pstack 来确定进程挂起的位置。此命令允许使用的唯一选项是要检查的进程的 PID;
这个命令在排查进程问题时非常有用,比如我们发现一个服务一直处于work状态(如假死状态,好似死循环),使用这个命令就能轻松定位问题所在;可以在一段时间内,多执行几次 pstack,若发现代码栈总是停在同一个位置,那个位置就需要重点关注,很可能就是出问题的地方。
2.命令语法
Usage: pstack <process-id>
3.常用用例
3.1.常用用法
# 1.使用ps查看相应的进程ID
[root@node4 ~]# ps -ef | grep postgres
postgres 19804 1 0 07:05 ? 00:00:00 /usr/pgsql-15/bin/postmaster -D /home/postgres/data/
postgres 19806 19804 0 07:05 ? 00:00:00 postgres: logger
postgres 19807 19804 0 07:05 ? 00:00:00 postgres: checkpointer
postgres 19808 19804 0 07:05 ? 00:00:00 postgres: background writer
postgres 19810 19804 0 07:05 ? 00:00:00 postgres: walwriter
postgres 19811 19804 0 07:05 ? 00:00:00 postgres: autovacuum launcher
postgres 19812 19804 0 07:05 ? 00:00:00 postgres: logical replication launcher
root 30002 22559 0 20:16 pts/0 00:00:00 grep --color=auto postgres
# 2.通过进程ID追踪堆栈信息
[root@node4 ~]# pstack 19804
#0 0x00007f911f3faf53 in __select_nocancel () from /lib64/libc.so.6
#1 0x00000000004931f5 in ServerLoop ()
#2 0x000000000074cc0d in PostmasterMain ()
#3 0x0000000000494876 in main ()
[root@node4 ~]#
1550

被折叠的 条评论
为什么被折叠?



