Java进程列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6283167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List of Java processes
提问by Jacek Koralik
How can I list all Java processes in bash?
I need an command line. I know there is command ps
but I don't know what parameters I need to use.
如何在 bash 中列出所有 Java 进程?我需要一个命令行。我知道有命令,ps
但我不知道需要使用哪些参数。
回答by Rich
try:
尝试:
ps aux | grep java
and see how you get on
看看你如何相处
回答by jm666
ps axuwww | grep java | grep -v grep
The above will
以上将
- show you all processes with long lines (arg: www)
- filter (grep) only lines what contain the word java, and
- filter out the line "grep java" :)
- 用长行向您展示所有进程(arg:www)
- 过滤器 (grep) 只包含包含单词 java 的行,以及
- 过滤掉“grep java”行:)
(btw, this example is not the effective one, but simple to remember) ;)
(顺便说一句,这个例子不是有效的,但很容易记住);)
you can pipe the above to another commands, for example:
您可以将上述内容通过管道传输到另一个命令,例如:
ps axuwww | grep java | grep -v grep | sed '.....' | while read something
do
something_another $something
done
etc...
等等...
回答by anubhava
回答by Nicholas Sushkin
Recent Java comes with Java Virtual Machine Process Status Tool "jps"
最近的 Java 自带 Java 虚拟机进程状态工具“jps”
http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html
http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html
For example,
例如,
[nsushkin@fulton support]$ jps -m
2120 Main --userdir /home/nsushkin/.netbeans/7.0 --branding nb
26546 charles.jar
17600 Jps -m
回答by krzysiek.ste
If I want simply list java processes, use:
如果我只想列出 java 进程,请使用:
ps -A | grep java
回答by airbjorn
When I want to know if a certain Java class is getting executed, I use the following command line:
当我想知道某个 Java 类是否正在执行时,我使用以下命令行:
ps ww -f -C java | grep "fully.qualified.name.of.class"
From the OS side view, the process's command name is "java". The "ww" option widens the colum's maximum characters, so it's possible to grep the FQN of the related class.
从操作系统的角度来看,进程的命令名称是“java”。"ww" 选项扩大了列的最大字符数,因此可以 grep 相关类的 FQN。
回答by Jude Niroshan
This will return all the running java processes in linux environment. Then you can kill the process using the process ID.
这将返回 linux 环境中所有正在运行的 java 进程。然后您可以使用进程 ID 终止该进程。
ps -e|grep java
回答by kiran jallepalli
To know the list of java running on the linux machine. ps -e | grep java
要知道在 linux 机器上运行的 java 列表。ps -e | 爪哇
回答by tinned_sardine
jps -lV
is most useful. Prints just pid and qualified main class name:
是最有用的。仅打印 pid 和限定的主类名称:
2472 com.intellij.idea.Main
11111 sun.tools.jps.Jps
9030 play.server.Server
2752 org.jetbrains.idea.maven.server.RemoteMavenServer
回答by jbrios777
There's a lot of ways of doing this. You can use java.lang.ProcessBuilder
and "pgrep" to get the process id (PID) with something like: pgrep -fl java | awk {'print $1'}
. Or, if you are running under Linux, you can query the /proc
directory.
有很多方法可以做到这一点。您可以使用java.lang.ProcessBuilder
和“p纤ep”的东西,如获得进程ID(PID) pgrep -fl java | awk {'print $1'}
。或者,如果您在 Linux 下运行,则可以查询/proc
目录。
I know, this seems horrible, and non portable, and even poorly implemented, I agree. But because Java actually runs in a VM, for some absurd reason that I can't really figure out after more then 15 years working the JDK, is why it isn't possible to see things outside the JVM space, it's really ridiculous with you think about it. You can do everything else, even fork
and join
child processes (those were an horrible way of multitasking when the world didn't know about threadsor pthreads, what a hell! what's going in on with Java?! :).
我知道,这看起来很糟糕,而且不可移植,甚至实现得很差,我同意。但是因为 Java 实际上在 VM 中运行,出于某种荒谬的原因,在使用 JDK 超过 15 年后我无法真正弄清楚,这就是为什么不可能看到 JVM 空间之外的东西,这对你来说真的很荒谬想想看。你可以做任何其他事情,甚至fork
和join
子进程(当世界不知道线程或pthreads 时,这是一种可怕的多任务处理方式,真见鬼!Java 怎么了?!:)。
This will give an immense discussion I know, but anyways, there's a very good API that I already used in my projects and it's stable enough (it's OSS so you still need to stress test every version you use before really trusting the API): https://github.com/jezhumble/javasysmon
我知道这将进行大量讨论,但无论如何,我已经在我的项目中使用了一个非常好的 API,并且它足够稳定(它是 OSS,因此您仍然需要在真正信任 API 之前对您使用的每个版本进行压力测试):https ://github.com/jezhumble/javasysmon
JavaDoc: http://jezhumble.github.io/javasysmon/, search for the class com.jezhumble.javasysmon.OsProcess
, she will do the trick. Hope it helped, best of luck.
JavaDoc:http: //jezhumble.github.io/javasysmon/,搜索类com.jezhumble.javasysmon.OsProcess
,她会做的。希望能帮到你,祝你好运。