Linux(Centos 7.6)命令详解:pstack

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 ~]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

豆是浪个

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值