Merge pull request #1 from fengyuhetao/master

1
pull/6/head
KaliArch 2019-05-13 17:31:50 +08:00 committed by GitHub
commit 86e5e637ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -1,3 +1,2 @@
# shell
2016-05-12 ~ 2016-05-22
所有案例均出自《Linux命令行与shell脚本编程大全案例》一书作为学习shell的一个见证
大部分所有案例均出自《Linux命令行与shell脚本编程大全案例》一书方便各位小伙伴学习欢迎各位同学共同扩充shell脚本库哦

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# 来源: https://blog.csdn.net/qianghaohao/article/details/80379118
# 服务器线程数达到 2500 以上时 dump 线程数最多的 java 进程的线程及内存
#
source ~/.bashrc
cur_thread_num=`ps -efL | wc -l`
if [ $cur_thread_num -le 2500 ]; then
exit 0
fi
cur_date=`date +"%Y-%m-%d_%H-%M-%S"`
cd ./dumpfile
# 服务器当前线程 dump 到文件:按照线程数由大到小排序显示
ps -efL --sort -nlwp > server_thread_dump_$cur_date
# dump 线程数最多的 jvm 的线程及内存
most_thread_num_pid=`cat server_thread_dump_$cur_date | sed -n '2p' | awk '{print $2}'`
nohup jstack -l $most_thread_num_pid > java_app_thread_dump_${cur_date}_pid_${most_thread_num_pid} &
nohup jmap -dump:format=b,file=java_app_mem_dump_${cur_date}_pid_${most_thread_num_pid} $most_thread_num_pid &
exit 0