如何在操作系统中给java进程命名(java除外) [英] How to give the java process a name in the operating system (other than java)
问题描述
我正在玩一些微服务并在我的笔记本电脑上运行它们,只需为每个微服务分配一个新端口。问题是我想重新启动其中一个我必须关闭它们因为在操作系统中进程都被称为java。虽然我有时可以猜到最后一次开始有最高的pid等是不是一个安全的赌注...
I'm playing around with some microservices and running them on my laptop, simply assigning each micro-service a new port. The problem is that I'd like to restart one of them I have to close them all because in the operating system the processes are all called java. And although I sometime can guess that the last started have the highest pid etc is isn't exacly a safe bet...
所以,有没有办法开始一个java-application并在操作系统中为其指定名称?也许类似
So, is there a way to start a java-application and assign it a name in the operating system? Perhaps something like
java --Dos.name MyFirstService -jar MyJar.jar。
推荐答案
如果你需要能够区分不同的java程序,你可以使用jps命令,它给你一个所有java进程的列表并运行你的程序with
If you need to be able to differentiate between different java programs you can use the jps command that gives you a list of all java processes and running your program with
java -Dname=myFirstService -cp myFirstService.jar some.client.main.MyFirstService
然后如果你这样做:
jps -v
您将看到正确的流程。
如果您需要在操作系统级别更改进程名称,我建议您使用 http://launch4j.sourceforge .net /
If you need to change the process name at the OS level I recommend you use http://launch4j.sourceforge.net/
这篇关于如何在操作系统中给java进程命名(java除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!