列出正在运行的虚拟机进程,并显示虚拟机执行主类(main class, main()函数所在的类)名称,以及这些进程的本地虚拟机Id(LVMID)。
###使用方法:在当前命令行下打jps(jps存放在JAVA_HOME/bin/jps,使用时为了方便请将JAVA_HOME/bin/加入到Path) 。
➜ ~ jps
7808 Launcher
2803 Main
5635 RemoteJdbcServer
5254 RemoteJdbcServer
13640 Jps
3400 RemoteMavenServer
5480 Main
7694 CosumerAckTest
22606 RemoteJdbcServer
4287 RemoteJdbcServer
##参数
-q 只显示pid,不显示class名称,jar文件名和传递给main方法的参数
➜ ~ jps -q
7808
2803
5635
5254
15240
3400
5480
7694
22606
4287
-m 输出传递给main方法的参数,在嵌入式jvm上可能是null
[@5fb59500efa6 ~]$ jps -m
42229 App /opt/src/app/config/zk.json
12317 Jps -m
-l 输出应用程序main class的完整package名或者应用程序的jar文件完整路径名
[@5fb59500efa6 ~]$ jps -l
12371 sun.tools.jps.Jps
42229 com.sohu.sns.reco.App
-v 输出传递给JVM的参数
[@5fb59500efa6 ~]$ jps -v
42229 App -Xms6114m -Xmx6114m -Xmn2200m -Xss256k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/logs/ -Djava.awt.headless=true -XX:MaxPermSize=512m -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dfile.encoding=UTF-8 -Dmonitor_agent_app_id=184461539_7eb18530-4ea0-11e8-ab05-00163e0f092d -Denv=PRODUCT -Dlogback.configurationFile=/opt/src/config/logback.xml
12414 Jps -Denv.class.path=./:/opt/apps/jdk/lib:/opt/apps/jdk/lib/tools.jar -Dapplication.home=/opt/apps_install/jdk1.7.0 -Xms8m
sun.jvm.hotspot.debugger.DebuggerException: Can’t attach to the process
➜ ~ jinfo 31983
Attaching to process ID 31983, please wait…
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can’t attach to the process
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can’t attach to the process
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(LinuxDebuggerLocal.java:163)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:278)
at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:671)
at sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:611)
at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:337)
at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304)
at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:185)
at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
at sun.jvm.hotspot.tools.JInfo.main(JInfo.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.tools.jinfo.JInfo.runTool(JInfo.java:108)
at sun.tools.jinfo.JInfo.main(JInfo.java:76)
Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can’t attach to the process
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.access$100(LinuxDebuggerLocal.java:62)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal 1 A t t a c h T a s k . d o i t ( L i n u x D e b u g g e r L o c a l . j a v a : 269 ) a t s u n . j v m . h o t s p o t . d e b u g g e r . l i n u x . L i n u x D e b u g g e r L o c a l 1AttachTask.doit(LinuxDebuggerLocal.java:269) at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal 1AttachTask.doit(LinuxDebuggerLocal.java:269)atsun.jvm.hotspot.debugger.linux.LinuxDebuggerLocalLinuxDebuggerLocalWorkerThread.run(LinuxDebuggerLocal.java:138)
解决办法:
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope