如何为 Java 程序设置进程名称? [英] How can I set the process name for a Java-program?
问题描述
如果一个 Java 程序被启动,它会在系统进程监控中得到名称 java.许多 Java 程序很难区分.因此,如果存在一种方法来设置名称会很好,这将显示在进程监视器中.我知道这在不同的操作系统上可能会有所不同.
If a Java program is started, it get's in the system process-monitor the name java. Many Java-programs are that way hard to distinguish. So it would be nice, if a way exists, to set the name, that will be shown in the process-monitor. I'm aware that this may work different on different Operating Systems.
一个简单的方法是,如果 java 解释器支持一个开关来设置名称,就像这样:
A simple way would be, if the java-interpreter would support a switch to set the name, like this:
java -processname MyProgram -jar MyProgram
但是我找不到这样的开关,所以它可能不存在.Java 中用于设置进程名称的 API 也可以.
But I couldn't find such a switch, so it is probably non-existant. An API in Java to set the process-name would be also fine.
那么,您有什么建议吗?
So, so you have any suggestions?
推荐答案
我不知道这是否可行,但您可以使用 JDK 附带的名为jps"的命令行工具.它就像 *nix ps
,但只是 Java 程序.jps -v
显示你传递给 java 的所有参数.
I don't know if this is possible, but you could use a command line tool that comes with the JDK called 'jps'. It's like *nix ps
, but just Java programs instead. jps -v
shows all the arguments you have passed to java.
此外,我看到人们通过向 args 添加一个未使用的 -Dmyprocessname
来将进程名称"附加到他们的 java 进程.
Also, I have seen people attach a "process name" to their java processes by adding an unused -Dmyprocessname
to the args.
这篇关于如何为 Java 程序设置进程名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!