如何使用ps -axl查找在Linux上运行的Java线程? [英] How to find a Java thread running on Linux with ps -axl?
问题描述
我有一个运行JVM,有两个线程。是否可以使用ps -axl在我的Linux操作系统上看到这些正在运行的线程?我试图找出操作系统给我的线程的优先级。关于这个问题的更多信息这里。
I have a running JVM with two threads. Is it possible to see these running threads on my Linux OS with ps -axl ? I am trying to find out what priority the OS is giving to my threads. More info about this other issue here.
推荐答案
使用
jps -v
用于查找java进程。示例输出:
for finding your java process. Sample Output:
3825 RemoteMavenServer -Djava.awt.headless=true -Xmx512m -Dfile.encoding=MacRoman
6172 AppMain -Didea.launcher.port=7533 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA 10.app/bin -Dfile.encoding=UTF-8
6175 Jps -Dapplication.home=/Library/Java/JavaVirtualMachines/1.6.0_31-b04-411.jdk/Contents/Home -Xms8m
然后使用
jstack 6172
(6172是你的进程的id)来获取jvm中的一堆线程。可以从中找到线程优先级。样本输出:
(6172 is id of your process) to get stack of threads inside jvm. Thread priority could be found from it. Sample output:
.....
"main" **prio=5** tid=7ff255800800 nid=0x104bec000 waiting on condition [104beb000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at au.com.byr.Sample.main(Sample.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
.....
享受!
编辑:如果应用程序运行在不同于您自己的用户(生产和其他非本地环境的典型案例)之后jps / jstack应该通过sudo运行。示例:
If application running under different user than yourself (typical case on production and other non-local environments) then jps/jstack should be run via sudo. Examples:
sudo jps -v
sudo jstack 6172
这篇关于如何使用ps -axl查找在Linux上运行的Java线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!