Linux进程占用cpu100%问题排查
传统方式
- 查看当前占用CPU较大的进程PID. 命令: top
- 定位具体业务模块. 命令: pwdx [PID]
- 定位具体项目(例如: 多个java进程) 命令: ps aux | grep [PID]
- 根据第一步获取到的PID找到对应的项目,查找进程中占用cpu较多的线程ID. 命令: top -Hp [PID]
- 将第二部获取到的线程ID转化为16进制. 命令: printf “0x%x\n” [线程PID]
- 通过java的jstack获取对应线程指定行数的堆栈信息. 命令: jstack [PID] | grep [线程PID] -A 50
使用示例
- top
- pwdx 101647
- ps aux | grep 101647
- top -Hp 101647
- printf “0x%x\n” 101647
- jstack 101647 | grep 19d45 -A 50
优化方式
利用工具
- 服务检测工具
- 脚本工具(例如: 阿里巴巴的show-busy-java-threads https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#-show-busy-java-threads)