日期:2014-05-16  浏览次数:20693 次

在Linux下使用top命令查看所有java进程的状态

在Linux下使用top命令查看所有java进程的状态

Bash脚本文件 jtop.sh

#!/bin/bash

#PIDS=$(ps -e | grep java | awk '{print $1}' | sed 's/^/-p/')
#top $PIDS

top $(ps -e | grep java | awk '{print $1}' | sed 's/^/-p/')

#END.

?

使用实例

[root@web java]# ./jtop.sh

top - 10:40:23 up 452 days, 14:10,? 6 users,? load average: 1.38, 0.91, 0.91
Tasks:?? 8 total,?? 0 running,?? 8 sleeping,?? 0 stopped,?? 0 zombie
Cpu(s):? 7.5%us,? 0.2%sy,? 0.0%ni, 92.0%id,? 0.0%wa,? 0.2%hi,? 0.2%si,? 0.0%st
Mem:?? 4075420k total,? 2164652k used,? 1910768k free,?? 139740k buffers
Swap:? 5406712k total,?? 265748k used,? 5140964k free,?? 627268k cached

? PID USER????? PR? NI? VIRT? RES? SHR S %CPU %MEM??? TIME+? COMMAND???????????????????????????????????????????????????????????????
20914 root????? 25?? 0 1446m 413m? 11m S 13.0 10.4?? 0:35.91 java??????????????????????????????????????????????????????????????????
?4797 root????? 20?? 0 1293m 120m 7952 S? 2.7? 3.0 908:25.78 java??????????????????????????????????????????????????????????????????
?4780 root????? 20?? 0 1153m 274m 6952 S? 0.0? 6.9 233:29.03 java??????????????????????????????????????????????????????????????????
10842 root????? 21?? 0 1202m 126m 7300 S? 0.0? 3.2 649:38.71 java??????????????????????????????????????????????????????????????????
24065 root????? 25?? 0 1200m 138m 7576 S? 0.0? 3.5 139:00.00 java??????????????????????????????????????????????????????????????????
25507 root????? 19?? 0 1144m? 24m 6960 S? 0.0? 0.6 256:47.51 java??????????????????????????????????????????????????????????????????
25521 root????? 25?? 0 1182m? 41m 7528 S? 0.0? 1.0 283:52.79 java??????????????????????????????????????????????????????????????????
28505 root????? 20?? 0 1140m? 24m 7240 S? 0.0? 0.6 276:55.52 java??

?

?

1 楼 tq02ksu 2011-10-28  
正常 来讲不建议所有 的程序都用root 来执行, 如果用其它用户执行的话正接
top -u $USER 就可以看的很清楚了
2 楼 hesihua 2011-11-09  
对我不管用
3 楼 codingstandards 2011-11-09  
hesihua 写道
对我不管用

为什么