java 如何知道 jar 文件是否已经在运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28785141/
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
How to know if a jar file is already running?
提问by crAlexander
After a research in google i found good answers like:
在谷歌研究后,我找到了很好的答案,例如:
1)using jpsor jps -lto get the jars running under JVM
1) 使用jps或jps -l来让 jars 在 JVM 下运行
OK with this answer but if the user has not java installed at all and i run my jar using for example a .bat file and a folder with java JRE.
好的,这个答案,但如果用户根本没有安装 java 并且我使用例如 .bat 文件和带有 java JRE 的文件夹运行我的 jar。
Also gps function is experimental and only JDK contais it and not JRE.
此外 gps 功能是实验性的,只有 JDK 包含它而不是 JRE。
2)Check if jar running from shell
I need a solution for this on windows platform.Although a platform indepedent solution is always prefferable.
我需要一个在 Windows 平台上的解决方案。尽管平台无关的解决方案总是可取的。
Something more about jps(cause it is Platform Independent) I will appreciate an answer where you provide me a good solution with jpsfunction.
关于 jps 的更多信息(因为它是平台独立的)我会很感激你为我提供一个带有jps功能的好的解决方案的答案。
回答by Andrew Piroli
You can us ps
and grep
on a *nix system as described above. For windows you can do:
您能给我们ps
和grep
在* nix系统上如上所述。对于 Windows,您可以执行以下操作:
tasklist /v /FI "IMAGENAME eq java.exe"
This will get you a list of all the Java programs running. I don't think you can get much closer on Windows.
这将为您提供所有正在运行的 Java 程序的列表。我不认为你可以在 Windows 上走得更近。
回答by Sireesh Vattikuti
use this command to check the jar is running or not.
使用此命令检查 jar 是否正在运行。
ps aux | grep java
eg:
例如:
sys_name 7526 60.1 2.6 4474364 104092 pts/4 Sl+ 23:57 0:09 java -jar start.jar
sys_name 7526 60.1 2.6 4474364 104092 pts/4 Sl+ 23:57 0:09 java -jar start.jar