Linux查看Java进程PID、端口号和内存占用脚本
superJps - Java进程监控脚本
1. 功能概述
superJps
是一个基于Bash的Java进程监控脚本,用于快速获取Linux系统中所有Java进程的详细信息。该脚本提供进程标识符(PID)、监听端口、内存占用和JAR路径/主类名称等关键信息,并附带系统级资源统计功能。
2. 核心功能
- 进程信息展示:实时显示所有Java进程的PID、端口、内存占用和启动参数
- 端口检测:自动识别进程监听的网络端口(未监听显示N/A)
- 精确内存计算:基于/proc文件系统计算实际物理内存占用(RSS)
- 资源统计:提供进程总数、端口监听数、内存总占用及系统内存占比
3. superJps 脚本
#!/bin/bash
export LC_ALL=C # 确保数字格式标准化TMP_FILE_PATH=/tmp/superJps.tmp
jps -ml > "$TMP_FILE_PATH"TOTAL_MEM=$(free -m | awk '/Mem:/ {print $2}') # 获取系统总内存(MB)
SUM_RSS=0 # 使用实际内存大小代替百分比
TOTAL_PROCESSES=0
PROCESSES_WITH_PORTS=0echo -e "PID\tPORT\tRSS(MB)\tJAR"while read -r LINE
doJPS_ARRAY=($LINE)PID=${JPS_ARRAY[0]}[ -z "$PID" ] && continue # 跳过空行# 获取实际内存使用(RSS) - 更可靠的方法RSS_KB=$(awk '/Rss:/ {sum += $2} END {print sum}' /proc/$PID/smaps 2>/dev/null)if [[ $RSS_KB -gt 0 ]]; thenRSS_MB=$((RSS_KB / 1024))SUM_RSS=$((SUM_RSS + RSS_MB))elseRSS_MB=0fi# 获取监听端口PORT=$(ss -tulnp 2>/dev/null | awk -v pid="$PID" '$1 == "tcp" && $2 ~ /LISTEN/ && $NF ~ pid,"java" {split($5, a, ":");port = a[length(a)];if (port ~ /^[0-9]+$/) print port}' | head -1)# 统计信息((TOTAL_PROCESSES++))[ -n "$PORT" ] && ((PROCESSES_WITH_PORTS++))# 输出进程信息echo -e "$PID\t${PORT:-N/A}\t${RSS_MB}\t${JPS_ARRAY[*]:1}"done < "$TMP_FILE_PATH"# 显示统计摘要
echo "========================================"
echo "Java进程总数: $TOTAL_PROCESSES"
echo "带端口监听: $PROCESSES_WITH_PORTS"
echo "内存总占用: ${SUM_RSS}MB"
echo "系统总内存: ${TOTAL_MEM}MB"
echo "内存占比: $(awk "BEGIN {printf \"%.1f%%\", ${SUM_RSS}/${TOTAL_MEM}*100}")"
4. 实现原理
4. 1. 进程信息获取
jps -ml > "$TMP_FILE_PATH"
使用JDK自带的jps命令获取所有Java进程的详细信息,输出到临时文件以供处理。
4.2. 内存计算机制
RSS_KB=(awk '/Rss:/ {sum += 2} END {print sum}' /proc/$PID/smaps 2>/dev/null)
通过解析/proc/[pid]/smaps文件的Rss字段,累计计算进程的实际物理内存占用,比简单的top或ps命令更加准确。
4.3. 端口检测方法
ss -tulnp 2>/dev/null | awk -v pid="$PID" '1 == "tcp" && 2 ~ /LISTEN/ && $NF ~ pid,"java" {split($5, a, ":");port = a[length(a)];if (port ~ /^[0-9]+$/) print port}' | head -1
使用ss命令(替代netstat)检测网络连接,通过PID匹配筛选出Java进程监听的端口。
4.4. 统计功能
脚本实时统计:
- 进程总数
- 带端口监听的进程数量
- 内存总占用(MB)
- 系统总内存(MB)
- 内存占比百分比
5. 使用方法
5.1 基本使用
vim /root/bin/superJps
# 复制 3. superJps 脚本 内容保存
vim /etc/profile
export PATH=$PATH:/root/bin
source /etc/profile
输出示例
[root@localhost bin]# superJps
PID PORT RSS(MB) JAR
1280 11159 284 /root/zhihuitushu/zhihuitushu-0.0.1-SNAPSHOT.jar
1282 11192 256 /root/fuzhuangshangcheng/fuzhuangshangcheng-0.0.1-SNAPSHOT.jar
1283 11195 284 /root/kehuguanxiguanli/kehuguanxiguanli-0.0.1-SNAPSHOT.jar
1284 11130 256 /root/springbooti8ts3/springbooti8ts3-0.0.1-SNAPSHOT.jar
1285 11166 275 /root/changguiyingji/changguiyingji-0.0.1-SNAPSHOT.jar
1287 11041 254 /root/springbootrpj39/springbootrpj39-0.0.1-SNAPSHOT.jar
1289 11102 288 /root/springboot073x3/springboot073x3-0.0.1-SNAPSHOT.jar
16393 11154 266 /root/gaoxiaobangongxingzheng/gaoxiaobangongxingzheng-0.0.1-SNAPSHOT.jar
1290 11107 276 /root/springbootrd362/springbootrd362-0.0.1-SNAPSHOT.jar
1292 11167 251 /root/xianshangfudaoban/xianshangfudaoban-0.0.1-SNAPSHOT.jar
10252 11140 270 /root/springbooteuw84/springbooteuw84-0.0.1-SNAPSHOT.jar
1293 11056 254 /root/springbootts2gs/springbootts2gs-0.0.1-SNAPSHOT.jar
1294 11184 264 /root/jibingfangkong/jibingfangkong-0.0.1-SNAPSHOT.jar
9998 11068 280 /root/springbootq9xc1/springbootq9xc1-0.0.1-SNAPSHOT.jar
9743 11084 272 /root/springboot142f7/springboot142f7-0.0.1-SNAPSHOT.jar
1296 11146 288 /root/springboot54r3f/springboot54r3f-0.0.1-SNAPSHOT.jar
11025 11088 278 /root/springbootr0p7i/springbootr0p7i-0.0.1-SNAPSHOT.jar
1299 11148 279 /root/chongwulingyangxitong/chongwulingyangxitong-0.0.1-SNAPSHOT.jar
11027 11145 293 /root/linyechanpintuijian/linyechanpintuijian-0.0.1-SNAPSHOT.jar
1301 11149 253 /root/huaqiangbeiershoushojiushangcheng/huaqiangbeiershoushojiushangcheng-0.0.1-SNAPSHOT.jar
8981 11118 255 /root/springbootu521z/springbootu521z-0.0.1-SNAPSHOT.jar
12053 11161 263 /root/renliziyuanguanli/renliziyuanguanli-0.0.1-SNAPSHOT.jar
8982 11065 276 /root/springbootww862/springbootww862-0.0.1-SNAPSHOT.jar
1303 11015 260 /root/springbootvtgh9/springbootvtgh9-0.0.1-SNAPSHOT.jar
8984 11099 264 /root/springbootx877q/springbootx877q-0.0.1-SNAPSHOT.jar
1305 11044 286 /root/ONLYzaixianshangcheng/ONLYzaixianshangcheng-0.0.1-SNAPSHOT.jar
8990 11078 279 /root/springbootr6il1/springbootr6il1-0.0.1-SNAPSHOT.jar
10527 11121 305 /root/springboot8525u/springboot8525u-0.0.1-SNAPSHOT.jar
1312 11081 276 /root/springboot94sk3/springboot94sk3-0.0.1-SNAPSHOT.jar
1315 11133 272 /root/wangshangshangchengB/wangshangshangchengB-0.0.1-SNAPSHOT.jar
1316 11096 242 /root/springbootil05r/springbootil05r-0.0.1-SNAPSHOT.jar
1317 11191 275 /root/lexiangtianyuan/lexiangtianyuan-0.0.1-SNAPSHOT.jar
1318 11026 261 /root/springbootbqv00/springbootbqv00-0.0.1-SNAPSHOT.jar
1320 11129 267 /root/springboot5h4b7/springboot5h4b7-0.0.1-SNAPSHOT.jar
9000 11052 263 /root/springboot1o52x/springboot1o52x-0.0.1-SNAPSHOT.jar
1321 11181 250 /root/shequyiyuan/shequyiyuan-0.0.1-SNAPSHOT.jar
1322 11010 513 /root/stuinfosystem/demo-0.0.1-SNAPSHOT.jar
1323 11035 261 /root/wangshangchaoshi/wangshangchaoshi-0.0.1-SNAPSHOT.jar
9003 11059 291 /root/springbootus5uu/springbootus5uu-0.0.1-SNAPSHOT.jar
1324 11046 283 /root/springboot2yx3h/springboot2yx3h-0.0.1-SNAPSHOT.jar
1327 11019 326 /root/springboot57n6g/springboot57n6g-0.0.1-SNAPSHOT.jar
1328 11170 257 /root/shehuizhihuiyanglaojianhu/shehuizhihuiyanglaojianhu-0.0.1-SNAPSHOT.jar
11312 11081 251 /root/springbootk6oce/springbootk6oce-0.0.1-SNAPSHOT.jar
9010 11054 283 /root/springbootsw863/springbootsw863-0.0.1-SNAPSHOT.jar
1333 11060 266 /root/springboot60m3k/springboot60m3k-0.0.1-SNAPSHOT.jar
12086 11171 282 /root/springbootmf383/springbootmf383-0.0.1-SNAPSHOT.jar
1334 11020 258 /root/springboot1hme0/springboot1hme0-0.0.1-SNAPSHOT.jar
10294 11134 274 /root/springboot3n829/springboot3n829-0.0.1-SNAPSHOT.jar
11062 11114 275 /root/springboot0e3m2/springboot0e3m2-0.0.1-SNAPSHOT.jar
9015 11062 269 /root/springbootul0e4/springbootul0e4-0.0.1-SNAPSHOT.jar
1336 11150 267 /root/tiyuguan/tiyuguan-0.0.1-SNAPSHOT.jar
9017 11025 272 /root/springbooth7te4/springbooth7te4-0.0.1-SNAPSHOT.jar
1338 11141 266 /root/springboot08hr3/springboot08hr3-0.0.1-SNAPSHOT.jar
1342 11177 255 /root/yiyuanhoutaiguanli/yiyuanhoutaiguanli-0.0.1-SNAPSHOT.jar
14656 11189 298 /root/liulangcongwuguanli/liulangcongwuguanli-0.0.1-SNAPSHOT.jar
1344 11066 252 /root/springboot60a0e/springboot60a0e-0.0.1-SNAPSHOT.jar
9024 11038 283 /root/springboot93c4v/springboot93c4v-0.0.1-SNAPSHOT.jar
12353 11045 267 /root/springbootpx13e/springbootpx13e-0.0.1-SNAPSHOT.jar
1346 11069 274 /root/springboot7vkr1/springboot7vkr1-0.0.1-SNAPSHOT.jar
1347 11187 271 /root/jianshenfangguanli/jianshenfangguanli-0.0.1-SNAPSHOT.jar
1348 11109 263 /root/springbootwk338/springbootwk338-0.0.1-SNAPSHOT.jar
11338 11141 255 /root/springboot2142g/springboot2142g-0.0.1-SNAPSHOT.jar
10058 11030 271 /root/springboot1a8gh/springboot1a8gh-0.0.1-SNAPSHOT.jar
11340 11116 269 /root/springbootrze22/springbootrze22-0.0.1-SNAPSHOT.jar
20812 11158 279 /root/wendangguanli/wendangguanli-0.0.1-SNAPSHOT.jar
9037 11029 295 /root/springboot7w3d0/springboot7w3d0-0.0.1-SNAPSHOT.jar
21326 N/A 253 /root/wendangguanli/wendangguanli-0.0.1-SNAPSHOT.jar
13923 11196 254 /root/springboot212h6/springboot212h6-0.0.1-SNAPSHOT.jar
9833 11143 311 /root/springboot0b6e5/springboot0b6e5-0.0.1-SNAPSHOT.jar
12138 11080 283 /root/springbootj2zt8/springbootj2zt8-0.0.1-SNAPSHOT.jar
10602 11110 259 /root/springbootsudk0/springbootsudk0-0.0.1-SNAPSHOT.jar
10097 11199 293 /root/dianshangpingtai/dianshangpingtai-0.0.1-SNAPSHOT.jar
10867 11193 256 /root/springboot3lx4p/springboot3lx4p-0.0.1-SNAPSHOT.jar
14969 11179 289 /root/springbootd07er/springbootd07er-0.0.1-SNAPSHOT.jar
20097 11157 287 /root/xiaoyuansiwuzhaoling/xiaoyuansiwuzhaoling-0.0.1-SNAPSHOT.jar
10626 11092 253 /root/springbootqi5z1/springbootqi5z1-0.0.1-SNAPSHOT.jar
1157 11001 591 /root/campus-market/campus-market-0.0.1-SNAPSHOT.jar
1158 11033 317 /root/springboott7kpr/springboott7kpr-0.0.1-SNAPSHOT.jar
1159 11064 329 /root/springboot51rqt/springboot51rqt-0.0.1-SNAPSHOT.jar
1160 11011 278 /root/springbootp0eo6/springbootp0eo6-0.0.1-SNAPSHOT.jar
1161 11079 276 /root/springbootpist4/springbootpist4-0.0.1-SNAPSHOT.jar
1162 11185 333 /root/tushuguanli/tushuguanli-0.0.1-SNAPSHOT.jar
1163 11160 302 /root/springbootl8m1o/springbootl8m1o-0.0.1-SNAPSHOT.jar
1164 11162 253 /root/banganbuguanli/banganbuguanli-0.0.1-SNAPSHOT.jar
1165 11115 361 /root/springbooto97z9/springbooto97z9-0.0.1-SNAPSHOT.jar
20366 N/A 259 /root/xiaoyuansiwuzhaoling/xiaoyuansiwuzhaoling-0.0.1-SNAPSHOT.jar
9102 11131 295 /root/springbootx1786/springbootx1786-0.0.1-SNAPSHOT.jar
1167 11017 335 /root/springbootjeb55/springbootjeb55-0.0.1-SNAPSHOT.jar
11151 11067 254 /root/springboot4691l/springboot4691l-0.0.1-SNAPSHOT.jar
1168 11034 262 /root/springboot03445/springboot03445-0.0.1-SNAPSHOT.jar
1169 11163 256 /root/xiangqinwangzhan/xiangqinwangzhan-0.0.1-SNAPSHOT.jar
1170 11144 288 /root/springbootk3yl6/springbootk3yl6-0.0.1-SNAPSHOT.jar
10386 11138 271 /root/springbootq731f/springbootq731f-0.0.1-SNAPSHOT.jar
1172 11089 317 /root/springboot9qw88/springboot9qw88-0.0.1-SNAPSHOT.jar
10900 11077 265 /root/springbootil5n0/springbootil5n0-0.0.1-SNAPSHOT.jar
1174 11090 320 /root/springboot89nep/springboot89nep-0.0.1-SNAPSHOT.jar
10647 11125 291 /root/springbooth6iu7/springbooth6iu7-0.0.1-SNAPSHOT.jar
10136 11086 299 /root/springboot224bf/springboot224bf-0.0.1-SNAPSHOT.jar
1178 11197 269 /root/sheuquyanglaofuwu/sheuquyanglaofuwu-0.0.1-SNAPSHOT.jar
10138 11142 265 /root/springbootqi5ww/springbootqi5ww-0.0.1-SNAPSHOT.jar
1179 9002 620 /root/springboot4prsj/springboot4prsj-1.0-SNAPSHOT.jar
8859 11139 269 /root/springbootawwm9/springbootawwm9-0.0.1-SNAPSHOT.jar
1181 11042 288 /root/springboot33dng/springboot33dng-0.0.1-SNAPSHOT.jar
10654 11105 303 /root/springboot68ozj/springboot68ozj-0.0.1-SNAPSHOT.jar
1184 11051 290 /root/springboot43q56/springboot43q56-0.0.1-SNAPSHOT.jar
1185 11061 270 /root/springboot3v5bn/springboot3v5bn-0.0.1-SNAPSHOT.jar
1186 11072 330 /root/springboot707pd/springboot707pd-0.0.1-SNAPSHOT.jar
10658 11053 285 /root/springboot4r3y8/springboot4r3y8-0.0.1-SNAPSHOT.jar
1187 11048 273 /root/springbootyf10w/springbootyf10w-0.0.1-SNAPSHOT.jar
13731 11057 255 /root/springbootiv1oo/springbootiv1oo-0.0.1-SNAPSHOT.jar
1188 11172 301 /root/tiyuguanguanli/tiyuguanguanli-0.0.1-SNAPSHOT.jar
9381 11119 277 /root/springboot9n107/springboot9n107-0.0.1-SNAPSHOT.jar
1190 11155 277 /root/zaixianwenjuandiaocha/zaixianwenjuandiaocha-0.0.1-SNAPSHOT.jar
1194 11173 323 /root/meishishangcheng/meishishangcheng-0.0.1-SNAPSHOT.jar
1196 11031 301 /root/springboot35l3z/springboot35l3z-0.0.1-SNAPSHOT.jar
1199 11136 335 /root/springbootp5hkd/springbootp5hkd-0.0.1-SNAPSHOT.jar
1201 11152 322 /root/jiechuzhe/jiechuzhe-0.0.1-SNAPSHOT.jar
1202 11037 331 /root/springboott01gx/springboott01gx-0.0.1-SNAPSHOT.jar
1203 11014 352 /root/springbootw3o95/springbootw3o95-0.0.1-SNAPSHOT.jar
1205 11161 270 /root/springbootr2r43/springbootr2r43-0.0.1-SNAPSHOT.jar
1208 11171 296 /root/springboot34t91/springboot34t91-0.0.1-SNAPSHOT.jar
1210 11040 302 /root/feiwuzhiwenhua/feiwuzhiwenhua-0.0.1-SNAPSHOT.jar
1211 11012 284 /root/springbootjf5zc/springbootjf5zc-0.0.1-SNAPSHOT.jar
22972 N/A 248 /root/yiyuanziyuanguanli/yiyuanziyuanguanli-0.0.1-SNAPSHOT.jar
1214 11073 254 /root/springboot0w575/springboot0w575-0.0.1-SNAPSHOT.jar
1216 11036 295 /root/springbootpkh49/springbootpkh49-0.0.1-SNAPSHOT.jar
9920 11074 316 /root/springboot46869/springboot46869-0.0.1-SNAPSHOT.jar
1218 11104 261 /root/springboot6alf1/springboot6alf1-0.0.1-SNAPSHOT.jar
8898 11085 279 /root/springbootmts92/springbootmts92-0.0.1-SNAPSHOT.jar
8900 11112 244 /root/springboote2a78/springboote2a78-0.0.1-SNAPSHOT.jar
1223 11174 251 /root/dangyuanjiaoyuguanli/dangyuanjiaoyuguanli-0.0.1-SNAPSHOT.jar
1225 11022 292 /root/springboot2c1hu/springboot2c1hu-0.0.1-SNAPSHOT.jar
1226 11175 322 /root/keyangongzuoliang/keyangongzuoliang-0.0.1-SNAPSHOT.jar
1227 11183 303 /root/springboot49j18/springboot49j18-0.0.1-SNAPSHOT.jar
1228 11039 306 /root/springboot482k3/springboot482k3-0.0.1-SNAPSHOT.jar
1229 11083 281 /root/springbootg2g8t/springbootg2g8t-0.0.1-SNAPSHOT.jar
10446 11182 255 /root/ershouchejiaoyi/ershouchejiaoyi-0.0.1-SNAPSHOT.jar
1231 11076 280 /root/springboot9v464/springboot9v464-0.0.1-SNAPSHOT.jar
1233 11124 259 /root/springbootuaaa4/springbootuaaa4-0.0.1-SNAPSHOT.jar
9169 11123 277 /root/springboot97s0t/springboot97s0t-0.0.1-SNAPSHOT.jar
1235 11045 292 /root/springbootwwiwn/springbootwwiwn-0.0.1-SNAPSHOT.jar
30932 N/A 0 sun.tools.jps.Jps -ml
1236 11070 281 /root/springbootj8m2s/springbootj8m2s-0.0.1-SNAPSHOT.jar
1237 11047 273 /root/qianghuichapin/qianghuichapin-0.0.1-SNAPSHOT.jar
19158 11165 260 /root/zaixiankaoshixuexijiaoliu/zaixiankaoshixuexijiaoliu-0.0.1-SNAPSHOT.jar
12504 11200 279 /root/gongzuoliuchengguanli/gongzuoliuchengguanli-0.0.1-SNAPSHOT.jar
1240 11027 303 /root/springbootf3x3h/springbootf3x3h-0.0.1-SNAPSHOT.jar
9432 11147 293 /root/shoujishangcheng/shoujishangcheng-0.0.1-SNAPSHOT.jar
1241 11113 351 /root/springboot5j0wf/springboot5j0wf-0.0.1-SNAPSHOT.jar
9433 11050 296 /root/springbootf5kdg/springbootf5kdg-0.0.1-SNAPSHOT.jar
1242 11111 337 /root/springbootnp4n3/springbootnp4n3-0.0.1-SNAPSHOT.jar
1243 11188 325 /root/zhinengxuexipingtai/zhinengxuexipingtai-0.0.1-SNAPSHOT.jar
1244 11023 263 /root/springbootmt74k/springbootmt74k-0.0.1-SNAPSHOT.jar
9180 11058 272 /root/springboot2mc6m/springboot2mc6m-0.0.1-SNAPSHOT.jar
9950 11049 270 /root/springbootr4n67/springbootr4n67-0.0.1-SNAPSHOT.jar
1249 11097 281 /root/springbootx2t46/springbootx2t46-0.0.1-SNAPSHOT.jar
12771 11127 264 /root/springboot4j9k2/springboot4j9k2-0.0.1-SNAPSHOT.jar
1253 11043 281 /root/springbootm3kwm/springbootm3kwm-0.0.1-SNAPSHOT.jar
1254 11028 286 /root/muyingshangcheng/muyingshangcheng-0.0.1-SNAPSHOT.jar
1255 11075 276 /root/springboots3cpm/springboots3cpm-0.0.1-SNAPSHOT.jar
10216 11128 280 /root/springboot2eidg/springboot2eidg-0.0.1-SNAPSHOT.jar
1257 11120 284 /root/springboot4prsj/springboot4prsj-0.0.1-SNAPSHOT.jar
1258 11117 281 /root/springboot5r64w/springboot5r64w-0.0.1-SNAPSHOT.jar
1259 11169 275 /root/jingquminsuyuyue/jingquminsuyuyue-0.0.1-SNAPSHOT.jar
1260 11180 286 /root/springbootpr919/springbootpr919-0.0.1-SNAPSHOT.jar
1262 11194 277 /root/xiaoyuanwangshangshangpu/xiaoyuanwangshangshangpu-0.0.1-SNAPSHOT.jar
10481 11100 281 /root/springbootu6123/springbootu6123-0.0.1-SNAPSHOT.jar
12274 11183 297 /root/yimiaofabuhejiezhong/yimiaofabuhejiezhong-0.0.1-SNAPSHOT.jar
1266 11087 276 /root/springboot0t1t7/springboot0t1t7-0.0.1-SNAPSHOT.jar
1267 11103 274 /root/springbooted1p6/springbooted1p6-0.0.1-SNAPSHOT.jar
22771 11168 301 /root/yiyuanziyuanguanli/yiyuanziyuanguanli-0.0.1-SNAPSHOT.jar
1268 11016 286 /root/springboot547vl/springboot547vl-0.0.1-SNAPSHOT.jar
10484 11151 277 /root/xiyanghong/xiyanghong-0.0.1-SNAPSHOT.jar
1269 11063 283 /root/springbootx9rzc/springbootx9rzc-0.0.1-SNAPSHOT.jar
11253 11032 266 /root/springbootc8v27/springbootc8v27-0.0.1-SNAPSHOT.jar
1272 11024 289 /root/springboot6yjn8/springboot6yjn8-0.0.1-SNAPSHOT.jar
1276 9001 452 /root/xueshengshixiguanlixitong/xueshengshixiguanlixitong-0.0.1-SNAPSHOT.jar
1277 11127 261 /root/springbootjtw43/springbootjtw43-0.0.1-SNAPSHOT.jar
1278 11137 259 /root/springboote51e2/springboote51e2-0.0.1-SNAPSHOT.jar
11006 11126 256 /root/springboot59b1w/springboot59b1w-0.0.1-SNAPSHOT.jar
1279 11013 267 /root/springbootxs5o6/springbootxs5o6-0.0.1-SNAPSHOT.jar
========================================
Java进程总数: 181
带端口监听: 177
内存总占用: 51533MB
系统总内存: 92485MB
内存占比: 55.7%
配置说明
环境要求
- Linux操作系统
- JDK 1.6+(提供jps命令)
- ss命令(通常由iproute2包提供)
安装部署
- 保存脚本至
/root/bin/superJps
- 添加执行权限:
chmod +x /root/bin/superJps
- 确保jps命令在PATH环境变量中
临时文件
脚本使用/tmp/superJps.tmp
作为临时存储文件,会在执行完成后自动清理。
注意事项
- 需要root权限或对/proc目录有访问权限
- 内存统计排除共享内存,反映实际物理占用
- 端口检测仅显示首个监听端口
- 使用LC_ALL=C确保数字格式标准化
- 建议在相同语言环境的系统中使用
应用场景
- Java应用故障排查
- 服务器资源监控
- 应用部署验证
- 性能分析初步诊断
该脚本为系统管理员和开发人员提供了快速诊断Java应用状态的有效工具,结合了JDK工具和系统命令的优势,提供了比标准jps命令更丰富的监控信息。