检查正在运行的进程 - java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18639934/
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
Check processes that are running - java
提问by user2675649
I want to write a java application that is to be deployed on a unix box. I need to check the running processes - that are running on the box. Could someone show me an example / point me in the right direction?
我想编写一个要部署在 unix 机器上的 java 应用程序。我需要检查正在运行的进程 - 在盒子上运行。有人可以给我举个例子/指出我正确的方向吗?
采纳答案by ktm5124
If you want to find the running java processes, you can use
如果要查找正在运行的 java 进程,可以使用
ps -ef | grep java
ps -ef | grep java
If you need to check which ports are in use,
如果您需要检查正在使用的端口,
netstat -tupln
netstat -tupln
回答by Clauds
I came across some alternatives for ps aux | grep java
provided by Java that need less typing:
我遇到了一些ps aux | grep java
需要较少输入的 Java 提供的替代方案:
jcmd
and
和
jps -v
The option -v
will show the arguments passed to the JVM.
该选项-v
将显示传递给 JVM 的参数。
If you get process information unavailablethis could be because the process is running with OpenJDK.
If you are root and the process was started with a non-root user you can use the following to see the details (replace <user>
with the username):
如果您的进程信息不可用,这可能是因为该进程正在使用 OpenJDK 运行。如果您是 root 并且进程是由非 root 用户启动的,您可以使用以下命令查看详细信息(替换<user>
为用户名):
sudo -u <user> jps -v
Another nice feature of jcmd
is that you can display the Java version that a specific process uses (in case ps aux | grep java
does not show it), that's how I came across the two (replace <pid>
with the process id):
另一个不错的功能jcmd
是您可以显示特定进程使用的 Java 版本(以防ps aux | grep java
不显示),这就是我遇到这两个的方式(<pid>
用进程 ID替换):
jcmd <pid> VM.version