习惯性地便捷的jps
命令,快速获取java进程信息,可能会出现jps
显示不全的现象。
1、jps显示不全,只有一个signer
的进程,
songzehao@songzehao-virtual-machine:~$ jps -l
406384 com.lingshu.bsp.signer.Application
437937 sun.tools.jps.Jps
可以看到只有一个java进程,实际上是有更多进程。
2、ps
可以看到所有用户下的所有进程,包含了
docker
容器中的front
进程node-mgr
进程arthas
进程signer
进程songzehao@songzehao-virtual-machine:~$ ps -ef | grep java
root 404652 1 0 6月28 ? 00:41:09 /usr/local/jdk1.8.0_40/bin/java -Djdk.tls.namedGroups=secp256k1 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -Xmx256m -Xms256m -Xmn128m -Xss512k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/songzehao/0shuCodes/baas2/node-manager/dist/log/heap_error.log -cp conf/:apps/:lib/ com.lingshu.bsp.node.mgr.Application
songzeh+ 406384 1 0 6月28 pts/2 00:05:57 /usr/local/jdk1.8.0_40/bin/java -Dfile.encoding=UTF-8 -Xmx256m -Xms256m -Xmn128m -Xss512k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/songzehao/0shuCodes/baas2/signer/dist/log/heap_error.log -cp conf/:apps/:lib/ com.lingshu.bsp.signer.Application
root 408906 408874 1 6月28 ? 00:45:26 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djdk.tls.namedGroups=secp256k1 -Dfile.encoding=UTF-8 -Xmx256m -Xms256m -Xmn128m -Xss512k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/front/log/heap_error.log -Djava.library.path=/front/conf -cp conf/:apps/:lib/ com.lingshu.bsp.front.Application
root 409297 409262 1 6月28 ? 00:46:10 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djdk.tls.namedGroups=secp256k1 -Dfile.encoding=UTF-8 -Xmx256m -Xms256m -Xmn128m -Xss512k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/front/log/heap_error.log -Djava.library.path=/front/conf -cp conf/:apps/:lib/ com.lingshu.bsp.front.Application
root 409690 409658 1 6月28 ? 00:46:25 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djdk.tls.namedGroups=secp256k1 -Dfile.encoding=UTF-8 -Xmx256m -Xms256m -Xmn128m -Xss512k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/front/log/heap_error.log -Djava.library.path=/front/conf -cp conf/:apps/:lib/ com.lingshu.bsp.front.Application
root 417090 417000 0 6月28 ? 00:27:04 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djdk.tls.namedGroups=secp256k1 -Dfile.encoding=UTF-8 -Xmx256m -Xms256m -Xmn128m -Xss512k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/front/log/heap_error.log -Djava.library.path=/front/conf -cp conf/:apps/:lib/ com.lingshu.bsp.front.Application
root 421981 421950 0 6月28 ? 00:36:13 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djdk.tls.namedGroups=secp256k1 -Dfile.encoding=UTF-8 -Xmx256m -Xms256m -Xmn128m -Xss512k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/front/log/heap_error.log -Djava.library.path=/front/conf -cp conf/:apps/:lib/ com.lingshu.bsp.front.Application
root 437688 428642 0 10:57 pts/0 00:00:01 java -jar arthas-boot.jar
songzeh+ 437932 22583 0 11:14 pts/2 00:00:00 grep --color=auto java
3、可能容易被忽略,jps
只是获取当前用户下的所有java进程,root权限的用户可以获取到所有用户下的所有java进程,所以再用sudo jps
试试,
songzehao@songzehao-virtual-machine:~$ sudo jps -l
417090 com.lingshu.bsp.front.Application
437955 jdk.jcmd/sun.tools.jps.Jps
406384 com.lingshu.bsp.signer.Application
409297 com.lingshu.bsp.front.Application
404652 com.lingshu.bsp.node.mgr.Application
421981 com.lingshu.bsp.front.Application
408906 com.lingshu.bsp.front.Application
409690 com.lingshu.bsp.front.Application
437688 arthas-boot.jar
可以获取到所有用户下的所有java进程,同理可以su
切换到root用户,再jps
查看,
root@songzehao-virtual-machine:~# jps -l
417090 com.lingshu.bsp.front.Application
406384 com.lingshu.bsp.signer.Application
409297 com.lingshu.bsp.front.Application
404652 com.lingshu.bsp.node.mgr.Application
421981 com.lingshu.bsp.front.Application
437978 jdk.jcmd/sun.tools.jps.Jps
408906 com.lingshu.bsp.front.Application
409690 com.lingshu.bsp.front.Application
437688 arthas-boot.jar
4、arthas
启动后也可以获取java进程列表,试下arthas
在不同用户下启动,先在当前用户下启动,
songzehao@songzehao-virtual-machine:~/apps$ java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.6.2
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
[1]: 406384 com.lingshu.bsp.signer.Application
只能获取到当前用户的java进程,再到root用户下启动,
root@songzehao-virtual-machine:~/apps# java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.6.2
[INFO] Process 404652 already using port 3658
[INFO] Process 404652 already using port 8563
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
[1]: 404652 com.lingshu.bsp.node.mgr.Application
[2]: 417090 com.lingshu.bsp.front.Application
[3]: 406384 com.lingshu.bsp.signer.Application
[4]: 409297 com.lingshu.bsp.front.Application
[5]: 421981 com.lingshu.bsp.front.Application
[6]: 408906 com.lingshu.bsp.front.Application
[7]: 409690 com.lingshu.bsp.front.Application
获取到了所有用户下的所有java进程,跟jps
的表现一致。